IOS程序設置爲音頻類app使後臺運行

1.Info.plist裏設置選項Required background modes 添加item0:App plays audio or streams audio/video using AirPlay
這裏寫圖片描述

2.設置Capabilities -> Background Modes -> 勾選 Audio,AirPlay**
這裏寫圖片描述

3.在AppDelegate.m中實現
這裏寫圖片描述
- (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.
UIApplication* app = [UIApplication sharedApplication];
__block UIBackgroundTaskIdentifier bgTask;
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
if (bgTask != UIBackgroundTaskInvalid)
{
bgTask = UIBackgroundTaskInvalid;
}
});
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
if (bgTask != UIBackgroundTaskInvalid)
{
bgTask = UIBackgroundTaskInvalid;
}
});
});
}

4.以上設置只實現了程序後臺運行,要通過審覈 還需實現app爲音頻類app。