思路是在后台循环播放一段无声的音乐
第一步
在Background Models中勾选Audio,AirPlay,andPicture in Picture
第二步
- (AVAudioPlayer *)player
{
if (!_player)
{
NSURL *url = [[NSBundle mainBundle] URLForResource:@"sound.wav" withExtension:nil];
_player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
[_player prepareToPlay];
//一直循环播放
_player.numberOfLoops = -1;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
[session setActive:YES error:nil];
}
return _player;
}
- (IBAction)buttonClick:(id)sender
{
/** 播放声音 */
[self.player play];
}
总结:
- 比较费电
- 审核人员会问你你想干啥(需要录取一个视频给审核人员看)