每月彙整: 2013 年 2 月

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