问题
One of our apps uses an AudioManager class which handles playback of various audio files and it creates two AVAudioPlayer instances on init. Many of our methods work under the assumption that these two instances will never be nil, so we use the generic init method to create these two instances when the manager class's singleton is initialized, like this:
- (id)init
{
self = [super init];
if(self){
_pushPlayer = [[AVAudioPlayer alloc] init];
_queuePlayer = [[AVAudioPlayer alloc] init];
}
return self;
}
Is this the best way to do this? Probably not, but that's not the point. The point is, that 13.1 has some error in how AVAudioPlayers are allocated/deallocated. If you create an AVAudioPlayer this way, your app will crash when it tries to deallocate it. You will get an EXC_BAD_ACCESS for your audio player's pointer.
Further, attempting to modify the dummy player, such as setting the delegate (even to nil), will cause a similar crash.
Here it is happening to someone else.
And another one (thanks to @Larme.)
Our app runs totally fine on devices running iOS 13.0 and earlier. We installed the app from the App Store on devices running multiple versions and it only crashes on devices running at least 13.1.
I also noticed that the init method is not present anywhere on the official documentation for AVAudioPlayer, though the method is not deprecated and no warnings are given when you use it.
Don't use [[AVAudioPlayer alloc] init]
or AVAudioPlayer() for those of you who use Swift.
来源:https://stackoverflow.com/questions/58181247/psa-avaudioplayer-alloc-init-crashes-in-ios-13-1-and-avaudioplayer