背景声音不与X code 7的工作 [英] Background audio not working with Xcode 7
问题描述
我有一个电台播放器应用程序,其中流从在线电台的音频。我已经启用后台模式,就像这样:
I have a radio player app, which streams audio from online radio stations. I have background modes enabled, like so:
当我建有X code 6的应用程序,它的工作对所有设备和所有iOS版本到iOS版8.即使是在iPhone 6,后来更新到iOS 9此后的工作,我有更新为X code 7,现在当我建立与任何版本的iOS背景声音不工作在任何设备上运行它,它只是当应用程序被切换到后台停止。
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.
任何想法?
推荐答案
在你的plist确保它说:应用程序不能在后台运行是NO。
In your plist make sure where it says "Application does not run in background" is NO.
那么下面code添加到didFinishLaunchingWithOptions方法你对你appDelegate.m文件。
Then add the following Code to your your appDelegate.m file in didFinishLaunchingWithOptions Method.
NSError * sessionError =零;
NSError *sessionError = nil;
NSError * activationError =零;
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setCategory:
AVAudioSessionCategoryPlayback错误:&放大器; sessionError];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&sessionError];
[AVAudioSession sharedInstance] SETACTIVE:YES错误:&放大器; activationError];
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];
这篇关于背景声音不与X code 7的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!