这个应用程序是在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)时,启动后就会崩溃。
崩溃点周围的输出如下所示:
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:
的函数。关于音频处理的代码是:
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 下崩溃并出现奇怪的错误。谢谢你!
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.
The output around crash point looks like:
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'
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");
}
Please help me figure out why it crashes under iOS 4.3 with the strange error. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在运行时,会调用许多不在代码中的方法,但由于您进行的 API 调用而在幕后调用这些方法。
我不会关注正在调用的方法,而是关注它发送到的对象为何无法响应选择器。该对象可能被转换为错误的类型,因此没有继承正确的方法。 (在您显示的代码片段中,您没有显式转换
AVAudioSession *audio_session
。)另一个方向是检查您是否没有使用仅适用于 iOS 5 的其他 API 调用,这在后台正在调用此方法并因此产生错误。最后,如果您最近才将构建目标更改为包含 iOS 4.3,则可能只需要执行全新构建(Product > Clean),以便编译与 iOS 4.3 兼容的代码。
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.
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.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.
也许您可以尝试下面的代码片段,
我认为
audio_session = [[AVAudioSession sharedInstance] keep];
默认情况下会调度方法setMode:
。并且setMode:
仅在 iOS 5.0 及更高版本中可用(请参阅文档
)。或者您可以尝试注释掉代码:
默认情况下必须有一个方法调度
setMode:
。自己尝试一下。 :p尝试在 gdb 中使用
info malloc 0x706a7f0
来获取选择器发送到的对象。请注意,0x706a7f0
是崩溃输出中显示的地址,与第一个代码片段中的地址相同。另一个提示,您可以执行
make clean
(Poduct->Clean) 并rebuild
它。Maybe you can try the code snippet below
I think
audio_session = [[AVAudioSession sharedInstance] retain];
dispatchs the methodsetMode:
by default. And thesetMode:
is only available in iOS 5.0 and later(refer to theDoc
).Or you can try to comment out the code:
There must be a method dispatches the
setMode:
by default. Try yourself. :pTry
info malloc 0x706a7f0
in your gdb to get the object that the selector was sent to. Note, the0x706a7f0
is the address that shown in your crash output as the one in your first code snippet.And another tip, you might do
make clean
(Poduct->Clean) andrebuild
it.AVAudioSession
方法在文档中被标记为仅适用于 iOS 5 及更高版本。事实上鉴于 最近在文档中添加了模式,看起来音频会话模式在 iOS 之前根本不可用5.
The
AVAudioSession
methodIs marked in the documentation as being available only for iOS 5 and later. In fact given the recent addition of modes to the documentation, it looks like audio session modes are not available at all prior to iOS 5.