这个程序是在ios 5.0下开发和工作良好,但在ios 4.3下崩溃 [英] this app was developed and works fine under ios 5.0, but crashes under ios 4.3

查看:145
本文介绍了这个程序是在ios 5.0下开发和工作良好,但在ios 4.3下崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS 5.0下开发了一个iPhone应用程序,它工作正常。但是,当涉及到iOS 4.3(Base SDK =最新的iOS 5.0,编译器= Apple LLVM 3.0,部署目标= iOS 4.3),它会在启动后崩溃。

I developed an iPhone app under iOS 5.0, and it works fine. But when it comes to iOS 4.3(Base SDK = latest iOS 5.0, compiler = Apple LLVM 3.0, Deployment Target = iOS 4.3), it crashes after launching.

周围的崩溃点如下:

2011-12-06 16:25:08.177 FMWei[466:c203] -[AVAudioSession setMode:error:]: unrecognized selector sent to instance 0x706a7f0
2011-12-06 16:25:08.181 FMWei[466:c203] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AVAudioSession setMode:error:]: unrecognized selector sent to instance 0x706a7f0'

看起来像 AVAudioSession 在调用它时没有成员函数 setMode:error:。但奇怪的是,我没有调用名为 setMode:error:的函数。关于音频处理的代码是:

It looks like that AVAudioSession doesn't have a member function setMode:error: while I invoked it. But what's strange is that I didn't invoke a function whose name is setMode:error:. The code about audio processing is:

audio_session = [[AVAudioSession sharedInstance] retain];
audio_session_err = nil;
[audio_session setCategory: AVAudioSessionCategoryPlayAndRecord error:&audio_session_err];
NSLog(@"!");

UInt32 audioRouteOverride = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,sizeof (audioRouteOverride),&audioRouteOverride);
UInt32 allowMixing = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing);    

if (audio_session_err) 
{
    NSLog(@"audioSession: %@ %d %@", [audio_session_err domain], [audio_session_err code], [audio_session_err description]);
}
else
{
    audio_session_err = nil;
    [audio_session setActive:YES error:&audio_session_err];
    if (!audio_session_err) NSLog(@"audio session is activated successfully");
}

请帮助我找出为什么它崩溃在iOS 4.3与奇怪的错误。谢谢!

Please help me figure out why it crashes under iOS 4.3 with the strange error. Thank you!

推荐答案

在运行时,调用了许多不在代码中的方法,作为您已经进行的API调用的结果。

At runtime, lots of methods are called that are not in your code, but which are called behind the scenes as a result of the API calls you have made.

我不会关注被调用的方法,而是关注为什么被发送到的对象不能响应选择器。对象可能被转换为错误的类型,因此不是继承正确的方法。 (在你显示的代码片段中,你没有显式地转换 AVAudioSession * audio_session 。)另一个方向是检查你没有使用一些其他API调用只有iOS 5,在后台调用这个方法,从而产生错误。

I would focus not on the method that is being called, but on why the object it is sent to is unable to respond to the selector. The object could have been cast as the wrong type, and so is not inheriting the right methods. (In the code snippet you show, you don't explicitly cast AVAudioSession *audio_session.) The other direction is to check that you're not using some other API call that is iOS 5 only, which in the background is calling this method and thus generating the error.

最后,如果你最近改变你的构建目标包括iOS 4.3,你可能只需要做一个干净的构建(产品>清洁),以便它编译iOS 4.3兼容的代码。

Finally, if you're only recently changed your build target to include iOS 4.3, you may simply need to do a clean build (Product > Clean) so that it compiles iOS 4.3-compatible code.

这篇关于这个程序是在ios 5.0下开发和工作良好,但在ios 4.3下崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆