Reputation: 12149
I make phone call from my application using:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://XXXXXXXXXX"]];
When the user ends the call, the default Apple-provided Phone app goes to the background and my application resumes focus. This happens automatically.
Now here's what I want: I'd like to call a method every time (and only when) the user returns from a call.
I tried calling this method from applicationWillEnterForeground:
or applicationDidBecomeActive:
but these callbacks are fired at other times when the application is being launched from the background state(which I dont want).
I'd like to determine if my application is being launched from the background state or if it is returning from a phone call so I can perform a certain task only in the former case and not latter. Any ideas?
----EDIT----
Here's how I finally did it:
See: CallStateDisconnected only detected for incoming calls, not for calls made from my app
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self listenForCalls];
}
- (void)listenForCalls {
self.callCenter = [[CTCallCenter alloc] init];
self.callCenter.callEventHandler = ^(CTCall* myCall) {
NSString *call = myCall.callState;
if([call isEqualToString:CTCallStateDialing]) {
//do ur stuff
}
};
}
Upvotes: 3
Views: 655
Reputation: 955
You Can use telephony framework, Which provides you call states to determine the state of phone. You can find out detail from here: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/CTCall/Reference/Reference.html#//apple_ref/doc/uid/TP40009590
Upvotes: 2
Reputation: 8001
Why not save a flag indicating that your app sent the user to the phone call. When your applications becomes active, if the flag is set, do the return from phone call method.
ex.
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"DidStartPhoneCall"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://XXXXXXXXXX"]];
Then something like,
-(void)applicationDidBecomeActive {
BOOL activeFromCall = [[NSUserDefaults standardUserDefaults] objectForKey:"DidStartPhoneCall"]
if(activeFromCall && [activeFromCall boolValue] == YES) {
// do your method
}
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"DidStartPhoneCall"]; // reste flag
}
Upvotes: 1