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]; }
+ (void)initialize { // 後台播放,第三步,設置 音頻會話類型 AVAudioSession *session = [AVAudioSession sharedInstance]; // 類型是:播放和錄音 [session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; // 而且要激活 音頻會話 [session setActive:YES error:nil]; }