所以我讨厌不得不问这个问题,但我花了一段时间搜索Apple的文档和Google没有用。我只是试图为我的应用程序设置AVAudioSession类别,当applicationDidFinishLaunching时。我有一个播放音频流的应用程序,我希望它在应用程序进入后台时继续播放,所以我试图使用播放类别。这里是我的AppDelegate.m代码:在AppDelegate.m中设置AVAudioSession类别
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// Set AudioSession
NSError *sessionError = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&sessionError];
[[AVAudioSession sharedInstance] setActive:YES error:&sessionError];
[[AVAudioSession sharedInstance] setDelegate:self];
// create window and set up navigation controller
[window addSubview:myNavController.view];
[window makeKeyAndVisible];
}
# pragma mark -
# pragma mark AVAudioSession Delegate Methods
- (void)beginInterruption {
}
- (void)endInterruption {
}
- (void)endInterruptionWithFlags:(NSUInteger)flags {
}
- (void)inputIsAvailableChanged:(BOOL)isInputAvailable {
}
有了这个代码,音频淡出任何时候我打的home键,把 在后台的应用程序。任何帮助非常感谢,我希望它 是一个快速修复类型的答案任何人谁已经做到了这一点。