我的应用程序需要在后台运行音频。在iOS 6之前的版本中,通过添加
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
代码添加到适当的.plist文件中,但是在将phonegap项目部署到iOS 6时,此方法不再起作用。如何在iOS 6中解决此问题?
最佳答案
在MainController.h文件中,更改以下内容:
#import "MainViewController.h"
#import <AVFoundation/AVFoundation.h>
@implementation MainViewController
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError];
}
return self;
}
我不确定是否需要执行以下操作,但是我清理了项目(CMD + ALT + K),重新编译了PhoneGap / Cordova Lib(更改了目标并让其运行到模拟器),然后(再次更改了目标之后)已编译为应用程序再次,现在可以工作了!
当心:它仅适用于设备,不适用于模拟器
关于audio - 在Phonegap项目中的iOS 6上不再在后台播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13128145/