I have an ios app that continues to play music when it moves into background. Now, if there is a phone call, answered or not, the app does not resume to play music. For two days i ve been reading posts about this problem here.None of them solved my problem.
I m using an AVQueuePlayer object as I stream my music too when required. Now the delegate methods have been deprecated since ios6. So I am using Notications.
The amazing part is that the interruption end (phone call end) is notified, the code that plays music is also written but the app jus doesnt play music until it comes to foreground(that with another notification)
Here's my code
-(void)viewWillAppear
{.....
........
.....
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioInterruptionNotification:) name:AVAudioSessionInterruptionNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioInterruptionNotification:) name:UIApplicationDidBecomeActiveNotification object:nil]
}
-(void)audioInterruptionNotification:(NSNotification *) aNotification {
NSLog(@"Interrupt %@", aNotification);
NSDictionary *dict = [aNotification userInfo];
NSUInteger typeKey = [[dict objectForKey:@"AVAudioSessionInterruptionTypeKey"] unsignedIntegerValue]; NSLog(@"%d", typeKey);
if (typeKey == 0)
{
[avPlayer play];
NSLog(@"1.......");
}
else if (typeKey == 1)
{
[avPlayer play];
NSLog(@"3...............");
;
}
}
Also , Ive tried inducing delays by dispatch queue. Delegate methods dont seem to work. But gaana, saavn and official music app by apple resume after a call. So this is possible. I jus seem to miss out on something. If I use core telephony.I ll have to add an entire framework which will increase the size of the app. And if it is the only way.Please tell how.
Thanks.I really appreciate your time.
So i returned after a while now and i see my question still unanswered. Well I have solved my question. It turns out it was just one simple statement that was missing.
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
along with the code i ve written in my question.