步骤1:
info.plist文件中添加:Required background modes字段,里面的item 值选择:App plays audio or streams audio/video using AirPlay
步骤二:
在Appdelegate.m中:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//后台播放音乐 步骤二:
{
AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
[session setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
NSError *activationError = nil;
[session setActive:YES error:&activationError];
}
}
时间: 2024-10-13 10:13:47