1
嗨我有一个使用定位服务留在后台的计步器应用程序,现在我需要每1000步发出一声嘟嘟声。当应用程序在后台播放音频或声音
我想这样玩:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
NSURL *audioFileLocationURL = [[NSBundle mainBundle] URLForResource:@"beep" withExtension:@"mp3"];
success = [audioSession setActive:YES error:nil];
AVPlayerItem * item = [[AVPlayerItem alloc] initWithURL:audioFileLocationURL];
queuePlayer = [[AVQueuePlayer alloc] initWithItems:@[item]];
[queuePlayer play];
但它不玩,如果我运行此代码,而应用程序是在前台它不玩,但我运行它,而它的在背景中它什么都不做。
有什么想法?
谢谢!
此代码是否正在使用'UIBackgroundTaskIdentifier'执行,还是正在后台线程上运行? –
UIBackgroundTaskIdentifier – Ecarrion