iOS_33_音乐后台播放
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]; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。