Reputation: 1
I am trying to make my application that is in the background come to the foreground after a call is disconnected. Here is the code:
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:0123456789"]]){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:0123456789"]];
} else {
// Could not make call
}
CTCallCenter *c=[[CTCallCenter alloc] init];
c.callEventHandler=^(CTCall* call){
if(call.callState == CTCallStateDisconnected) {
// code to make app return to the foreground
// I have tried calling applicationWillEnterForeground, but it didn't work
}
}
Please help
Upvotes: 0
Views: 3026
Reputation: 14148
Apple will not allow you to "come to the foreground" but you can use a local notification instead.
So for what you want to do you need to:
After starting the dial url you will get a 'applicationDidEnterBackground:' as your app is pushed to the background. You will need to start a background task or else you will not get the call state change.
When you get a call state change, create a local notification. If the user wants to "view" your application then you app will come to the foreground.
There is one problem with the above, if the phone call is longer than 10 min's then the background task will be terminated you will not get your call state change.
Upvotes: 1
Reputation: 28688
I am fairly certain you can't do it with a simple call. Maybe registering a URL handler my app:// and usinng openURL in the completion block could work, but that seems quite hacky.
Upvotes: 1