Validate if call was made after telprompt - iphone

I want to validate if user tapped on Call button or Cancel button after telprompt
Current code:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#", [personDetails valueForKey:#"phone"]]];
[[UIApplication sharedApplication] openURL:url];
How can I do so?

First telprompt: is not a documented URL schema and should not be used. Since Apple can change the way it used at any moment.
Second since data is passed back to your app, you will not be able to detect a if call was made. You might be able to detect if you use the CoreTelephony. But getting this to work require your app to run in the background and you might have to misuse some background mode for this which will make Apple reject your app.
Can you explain why you want to detect if there was a call made?

[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(called:) name:#"UIApplicationSuspendedNotification" object:nil];
-(void)called:(NSNotification *) notification
{
NSLog(#"Tapped Call button");
}
if Call button was tapped then application will be terminated and go into background so just add an observer for the UIApplicationSuspendedNotification notification.

For my case, I used tel:// instead of using telprompt:// and make my own UIAlertView. This way you could detect if the call option is tapped from the UIAlertView's delegate.

Related

How to control unwanted Pop-up that appear when making call within app

I am developing an app about making call and returning to app when calling ended. Here is my code;
**callWebview = [[UIWebView alloc] init];
NSURL *telUrl=[NSURL URLWithString:#"tel:4444484"];
[callWebview loadRequest:[NSURLRequest requestWithURL:telUrl]];**
This is ok but when url request is being sent, A pop up appears on the screen.
This is the screenshot when I press the button and run the code at upside;
So , Here is my question;
Can I block this pop up to appear on the screen ?
If I can't how can I change the message body and buttons of this popup ?
Thanks...
If you do not use the UIWebView the message will not appear, but then you will not be able to come beck to the app.
To make a call with out the alert:
NSURL *telUrl=[NSURL URLWithString:#"tel:4444484"];
// Check if the iOS device support dialing a number
if ( [[UIApplication sharedApplication] canOpenURL:telUrl]) {
[[UIApplication sharedApplication] openURL:telUrl];
}
But there is no solution that will do exactly what you desire, so either it is the dialog or no dialog but not retuning to you app.
Try the following instead:
NSURL *telUrl=[NSURL URLWithString:#"tel:4444484"];
[[UIApplication sharedApplication] openURL:telUrl];

How to use NSThread with UILocalNotification to show custom view?

I am developing an application of Fake incoming call.
For that, i am right now using local notification.
I am getting notification as per the set time but it gives me the pop up, like a by default notification.
Instead this, i have to show the view from either XIB or by codeing.
So, is there any way to set the custom view with localnotification?
Or can i use NSThread to get the above mentioned output?
If anyother way to get the disered output, then please let me know.
Thanks in advance
This is what i am doing to set the notification.
-(void)addNotification
{
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
[localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:5]];
[localNotification setAlertAction:#"Answer"];
[localNotification setAlertBody:[NSString stringWithFormat:#"%#\n\n %#",[txt_CallerName text],[txt_CallerNumber text]]];
[localNotification setHasAction: YES];
[localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system
[alertNotification setHidden:NO];
}
Showing a custom interface on receiving a UILocalNotification is not possible right now. It is possible if you happen to receive the UILocalNotification when your app is in the foreground. But if it is in the foreground, you could show your custom interface regardless.
The way you catch the local notification firing and do something when that happens is by implementing -application:didReceiveLocalNotification: in UIApplicationDelegate. Arguably, it is the answer to your question, but it won't achieve what you're clearly looking for, which is to start your app at a specific point in time by showing custom UI, because it will only happen while the app is already in the foreground.
You can use NSNotificationCenter to throw notification and event occurred just call the notified method and display your custom view.
1.Register the Notification as follows:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(displayCustomView) name:#"EventNotification" object:nil];
2.When event occur notify method as follows:
[[NSNotificationCenter defaultCenter] postNotificationName:#"EventNotification" object:nil];
3.In notified method display your custom view as follows:
-(void)displayCustomView
{
//initialize custom view and display as required.
}

iPhone, call another phone number in response to the first not answering?

I am attempting to create an application that will initiate a call to a priority 1 contact on a call-center-like list.
Then, if that contact does not answer (let's forget the whole problem of answering machines here), I'd like to call the priority 2 contact, and so on, until one of them answers or I exhaust my list.
Is this possible?
I've tried the following:
Hook into the CTCallCenter.CallEventHandler event, and checking the call state for CTCallStateConnected and CTCallStateDisconnected, and I get it to respond to the fact that the call disconnected, without ever connecting, and then attempt to initiate another call like I did the first, but this second attempt just sits dead in the water.
Override the DidEnterBackground method, and periodically check the CTCall.CallState property, basically again trying to respond to a disconnect that was never connected, but this does not appear to work either
I also tried adding a short delay (1 second, 2.5 seconds and 10 seconds) after detecting the disconnected state before attempting the next dial, to allow for the phone application to "settle down" after aborting the call, this did not change anything.
I'm of the opinion that this is better solved at the destination of the phone call. I would either have the phone company configure a "follow me" service, use Twilio or some other 3rd party service (as already suggested), or configure my own PBX using something like Asterisk (Asterisk includes the ability to configure "follow me" type behavior). It provides you much more flexibility and control, even if you did find a way to do this natively in iOS.
Having said that, I did get this to work in iOS assuming the following:
Your app initiates the call.
The phone app is opened, dials the number, and disconnects.
The user explicitly returns to your app. If you managed to get the events while your app was backgrounded, I want to know more :-).
On return of control to your app, the phone events are sent and a new call is initiated.
I have the following snippet of code in my UIApplicationDelegate didFinishLaunchingWithOptions method:
// In appdelegate header, ct is declared as #property (strong, nonatomic) CTCallCenter *ct;
self.ct = [[CTCallCenter alloc] init];
self.ct.callEventHandler = ^(CTCall *call) {
if (call.callState == CTCallStateConnected) {
// do some state management to track the call
} else if (call.callState == CTCallStateDisconnected) {
// check that this is the expected call and setup the
// new phone number
NSURL *telURL = [NSURL URLWithString:myNewNumberURL];
[application openURL:telURL];
}
};
This will make the new call. I'm using the iOS 5 SDK; tested on an iPhone 4s.
EDIT:
Using Return to app behavior after phone call different in native code than UIWebView as a starting point, I've managed to get this to work. Note that I have punted on memory management for clarity. Assuming you use the web view technique for getting back to your app after the call is complete, try something like this in the call completed block:
else if (call.callState == CTCallStateDisconnected) {
// check that this is the expected call and setup the
// new phone number
NSURL *telURL = [NSURL URLWithString:myNewNumberURL];
dispatch_async(dispatch_get_main_queue(), ^{
UIWebView *callWebview = [[UIWebView alloc] init] ;
[self.window.rootViewController.view addSubview:callWebview];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
// and now callWebView sits around until the app is killed....so don't follow this to the letter.
});
}
However, this may not quite give you what you want either. The user will get an alert on each call request, providing an opportunity to cancel the call.
You could use http://labs.twilio.com/twimlets/findme. You could have the app call a Twilio number and it could use findme to call all the numbers in order.
I didn't take a deeper look at it, but the Deutsche Telekom SDK might contain what you're looking after:
http://www.developergarden.com/fileadmin/microsites/ApiProject/Dokumente/Dokumentation/ObjectiveC-SDK-2.0/en/interface_voice_call_service.html
I really am not sure though (don't have time to really look at it at the moment) - I just remembered I'd read somewhere that they have an iOS SDK that is supposed to also handle call management, so I'm posting the link here for you to find out (and hopefully tell us if it works).
#pragma mark -
#pragma mark Call Handler Notification
-(void)notificationCallHandler {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(callReceived:) name:CTCallStateIncoming object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(callEnded:) name:CTCallStateDisconnected object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(callConnected:) name:CTCallStateConnected object:nil];
}
-(void)callEnded:(NSNotification*)notification {
NSLog(#"callEnded");
}
-(void)callReceived:(NSNotification*)notification {
NSLog(#"callReceived");
}
-(void)callConnected:(NSNotification*)notification {
NSLog(#"callConnected");
}
May this will help you
if you wanna setup a new call, while app is in background, i dont see any proper way for this, a lil hack could be, getting location update (because u can get location updates while app is in background), and location service automatically wakes up your application when new location data arrives, and small amount of time is given to application in which u can execute some code, in that time you may start a new call.
u can read further here:
search this ''Starting the Significant-Change Location Service'' in this link Location Aware programming guide
, and read the paragraph that is written after the code block.

iPhone iOS 4: how do you go from background to foreground in objective-c

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
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.
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.

Restarting iPhone application after [UIApplication sharedApplication] openURL

As title says I'd like to know how to restart my iPhone app after doing this:
[[UIApplication sharedApplication] openURL:[NSURL UrlWithString:#"tel://0123456789"]]
It seems pretty simple as I saw many topics also talking about restoring the very state of the application when openURL is called, but I can't find how to simply restart the app when the calling is finished.
Is it supposed to be the default behavior? As for me, the iPhone opens Favorites after call is finished, I don't know why.
You can't. Starting an app is solely user's responsibility - which I consider a good thing.
check the discussion here: https://devforums.apple.com/message/128046#128046
create a UIWebView to load the phone url like this:
UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
just use
[[UIApplication sharedApplication] openURL:[NSURL UrlWithString:#"telprompt://0123456789"]]
It will return to the app after call finished
You can't restart an app after a phone call, as your app has terminated and your code is no longer being run.
If you want to restart after the user visits a webpage, you can put a link with a custom scheme in that webpage, and register it with your app. The user can then tap the link to open your app again.