My App is crashing on iOS 13.1 when i trace a issue then found App is crashing because of AVAudioPlayer
.
Below Is My Player Setup.
if le
I found a crash issue in AVAudioPlayer
with iOS 13.1.
Here Is Solution
Why My AVAudioPlayer
crash? because
I initialise AVAudioPlayer
like
var wrongMusicPlayer: AVAudioPlayer = AVAudioPlayer()
and then i try to reassign wrongMusicPlayer
as below
wrongMusicPlayer = try AVAudioPlayer(contentsOf: wrongURL)
And my app get crash.
Solution
If you initialise your AVAudioPlayer
like var wrongMusicPlayer: AVAudioPlayer = AVAudioPlayer()
OR wrongMusicPlayer = AVAudioPlayer()
in any method then please remove it and just Declare like var wrongMusicPlayer: AVAudioPlayer!
.
Thanks, Rakesh! It's amazing! My game broke on iPhone with iOS 13.1.2. But in simulator it's work. On physical device - no! I read a lot of forums, online books, docs, etc.
And this small fix really helped me:
I changed var player = AVAudioPlayer()
to var player: AVAudioPlayer!
p.s. guys wrote about problem with threads but this case is simpler
The same issue happens with Objective C code.
Previously musicPlayer = [[AVAudioPlayer alloc] init]; would work but will now cause a crash in iOS13. The crash happens later on when using one of the other init methods like initWithContentsOfURL.
Removing the [[AVAudioPlayer alloc] init] fixes the issue.
iOS 13.2, which be released today, fixes this issue.