Background audio not working with Xcode 7

2019-04-16 08:06发布

I have a radio player app, which streams audio from online radio stations. I have background modes enabled, like so: enter image description here

When I built the app with Xcode 6, it worked on all devices and all iOS versions up to iOS 8. It even worked on an iPhone 6 that was later updated to iOS 9. Since then, I have updated to Xcode 7 and now when I build and run it on any device with any iOS version the background audio does not work, it just stops when the app goes to background.

Any ideas?

1条回答
混吃等死
2楼-- · 2019-04-16 08:50

enter image description here

In your plist make sure where it says "Application does not run in background" is NO.

Then add the following Code to your your appDelegate.m file in didFinishLaunchingWithOptions Method.

NSError *sessionError = nil;

NSError *activationError = nil;

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&sessionError];

[[AVAudioSession sharedInstance] setActive: YES error: &activationError];

查看更多
登录 后发表回答