开发者

iOS4 - Background audio with iPhone Simulator

开发者 https://www.devze.com 2023-01-05 23:29 出处:网络
I un开发者_JAVA百科successfully tried to implement a playback audio that continues to play in background by setting the UIBackgroundModes property and by activating an audio session as Joshua Weinberg

I un开发者_JAVA百科successfully tried to implement a playback audio that continues to play in background by setting the UIBackgroundModes property and by activating an audio session as Joshua Weinberg suggested, but it doesn't work on the simulator and I have no chance to test on a device with iOS4. I read about of a possible issue with the simulator, is it likely? Is there anyone who has produced code that works on the simulator? Thanks and sorry because I originally posted it as answer (since no "add comment" link was enabled).


voidness,

It is working for me by implementing this code. This will not work in the simulator though for whatever reason. So if your code is the same or similar, have faith that it does work brilliantly on my iPod Touch with iOS4 installed.

App Delegate.m (either in init or applicationDidFinishLaunching)

- (id) init {   

    // allows you to play in the background when app is suspended in iOS4
    [[AVAudioSession sharedInstance] setDelegate: self];
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];

}

And of course be sure to set the UIBackgroundModes key to audio like was stated before.

Best of luck,

Rob


I found out that it actually possible to play background audio in iphone simulator by following this step... Entering background on iOS4 to play audio

0

精彩评论

暂无评论...
验证码 换一张
取 消