IOS App does not run in background
I want my app audio to run in background and I had followed this tutorial
but it doesn't worked. My app audio still stopped when I pressed home
button and I realised it did not call "applicationDidBecomeActive" or
"applicationDidEnterBackground" (problem continued even though I had
disabled the setting "Application does not run in background") too. I had
been dealing with this for the past week.
So far I had done this steps:
-Added AVFoundation framework and declared
#import <AVFoundation/AVFoundation.h>
-Set up AVAudioSession in audio
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];
}
-Add rows in plist
No comments:
Post a Comment