iOS Playing Audio In background

1.
在 Info.plist加上 “Required background modes” ( array )
Key => Item 0, Value => App plays audio

2.
在 AppDelegate.h 加上
#import <AVFoundation/AVFoundation.h>

3.
在 – (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
加上
/* Playing music in background START */

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL ok;
NSError *setCategoryError = nil;
ok = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];

/* Playing music in background END */

這樣就可以了…

ref.
http://stackoverflow.com/questions/12770487/html-5-audio-mp3-file-not-playing-back-when-iphone-locked-using-phonegap-2-1-0-a

發佈留言

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料