目标C -背景音频与红色指示



我的应用程序正在播放mp3音频文件,而用户正在搜索应用程序上的另一个活跃用户。

在我的app委托中,我请求更多后台时间来继续执行搜索:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        NSLog(@"Background handler called. Not running background tasks anymore.");
        [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
        self.backgroundTask = UIBackgroundTaskInvalid;
    }];
}

当用户将应用程序发送到后台时,音频继续播放,搜索算法继续工作。

但是,我希望在屏幕顶部有一个红色指示条,类似于您在后台应用程序上执行VOIP呼叫时所看到的。

这可能吗?

这是我的音频播放器代码在SearchView.m

NSString *path = [NSString stringWithFormat:@"%@/searchTune.mp3", [[NSBundle mainBundle] resourcePath]];
NSURL *soundUrl = [NSURL fileURLWithPath:path];
_audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
[_audioPlayer play];

不,不可能。没有公共API, iOS在内部使用私有API。

相关内容

最新更新