My problem is – when audio is playing in background in my iPad then “my app icon” is not coming. I am using iPodMusicPlayer. For playing audio in background I have write these code..
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
[super viewWillDisappear:animated];
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
// The iPod controls will send these events when the app is in the background
- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
if (receivedEvent.type == UIEventTypeRemoteControl) {
switch (receivedEvent.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
[self performSelector:@selector(playPause:)];
break;
case UIEventSubtypeRemoteControlPreviousTrack:
//[self previousSong:nil];
//[self performSelector:@selector(previousSong:)];
break;
case UIEventSubtypeRemoteControlNextTrack:
//[self performSelector:@selector(nextSong:)];
break;
default:
break;
}
}
}
and info.plist I have also set “required background mode”
You will also have to add
UIBackgroundModesto yourInfo.plistand set its value toaudio.Please check the iOS App Programming Guide, specifically the App States and Multitasking section for detailed info on how to execute tasks in background.
[UPDATE]
Also add these two lines to
application:didFinishLaunchingWithOptions:in yourAppDelegate.m:And this code when you start playing your audio:
This should do it. Tested in the simulator, as well as on a device.