app的beginBackgroundTaskWithExpirationHandler方法
开启后台任务,让程序在后台运行
- (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. // 后台播放三步骤之一:让应用在后台运行 [application beginBackgroundTaskWithExpirationHandler:nil]; }
initialize】中,设置音频会话的类型,并激活
+ (void)initialize { // 后台播放,第三步,设置 音频会话类型 AVAudioSession *session = [AVAudioSession sharedInstance]; // 类型是:播放和录音 [session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; // 而且要激活 音频会话 [session setActive:YES error:nil]; }
原文地址:http://blog.csdn.net/pre_eminent/article/details/39188759