我正在尝试解决此崩溃问题:
Thread 0 Crashed:
0 libobjc.A.dylib 0x0000000180274430 objc_msgSend + 16
1 Foundation 0x0000000181a132e4 __NSThreadPerformPerform + 340 (NSThread.m:1265)
2 CoreFoundation 0x0000000180fbf77c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1982)
3 CoreFoundation 0x0000000180fbf6fc __CFRunLoopDoSource0 + 88 (CFRunLoop.c:2017)
4 CoreFoundation 0x0000000180fbef84 __CFRunLoopDoSources0 + 204 (CFRunLoop.c:2053)
5 CoreFoundation 0x0000000180fbcb5c __CFRunLoopRun + 1048 (CFRunLoop.c:2920)
6 CoreFoundation 0x0000000180edcc58 CFRunLoopRunSpecific + 436 (CFRunLoop.c:3245)
7 GraphicsServices 0x0000000182d88f84 GSEventRunModal + 100 (GSEvent.c:2245)
8 UIKit 0x000000018a6355c4 UIApplicationMain + 236 (UIApplication.m:3956)
经过进一步调查,我发现崩溃发生在AVFAudio: 的 performSelector:withObject:finishedPlaying
我不确定是谁调用了这个,因为我没有调用这个函数,而且我没有实现AVAudioPlayer委托。
当用户点击某些内容时,我只是在播放音频。我最初的猜测是音频仍在播放,视图控制器被解雇。但是,我无法重现它。我打电话播放音频是这样的:
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[self.audioPlayer play];
当控制器消失时我称之为:
- (void) viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self.audioPlayer stop];
}
另外,我强烈要求AVAudioPlayer
@property (nonatomic, strong) AVAudioPlayer *audioPlayer;
不确定这是否会影响它,但我想确保用户即使在静音时也会听到声音:
NSError *setCategoryErr = nil;
NSError *activationErr = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];
TIA