gpt4 book ai didi

iphone - iOS App无法在后台运行

转载 作者:行者123 更新时间:2023-12-03 02:17:24 25 4
gpt4 key购买 nike

我希望我的应用程序音频在后台运行,但我遵循了this tutorial,但没有用。当我按下主页按钮时,我的应用程序音频仍然停止,并且我意识到它没有调用“applicationDidBecomeActive”或“applicationDidEnterBackground”(即使我禁用了“应用程序不在后台运行”设置,问题仍然存在)。过去一周我一直在处理这个问题。

到目前为止,我已经执行了以下步骤:

-添加了AVFoundation框架并声明了

#import <AVFoundation/AVFoundation.h>

-在音频中设置AVAudioSession
NSString *audioName = [NSString stringWithFormat:@"audio%d", (nimages)];
NSString *soundPath =[[NSBundle mainBundle]pathForResource:audioName ofType:@"mp3"];
NSURL *soundURL = [NSURL fileURLWithPath:soundPath];
NSError *error = nil;
AVAudioPlayer *audio = nil;
audio = [[AVAudioPlayer alloc]initWithContentsOfURL:soundURL error:&error];
audio.numberOfLoops = -1;
audio.volume = 0.9;
if (error) {
NSLog(@"%@", [error localizedDescription]);
NSLog(@"Unable to load file");
}else {
//Make sure the system follows our playback status
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
//Load the audio into memory
[audio prepareToPlay];
}

-在plist中添加行

更新:

我的应用程序是一个音频应用程序,即使它进入背景,用户也可以播放其特定音轨。可能吗?

最佳答案

我认为它必须积极播放音频才能正常工作。如果您的应用程序实际上不是音频应用程序,则可以尝试将其设置为VoIP。这不需要 Activity 的连接。它还不会阻止其他想要使用音频的应用程序。只需将后台模式设置为“应用程序提供IP语音服务”,即可一次在后台运行长达十分钟;您可以连接VoIP套接字并将内容推送到其中,如果要使其保持 Activity 状态或也要唤醒。

关于iphone - iOS App无法在后台运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18641474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com