2

How would I make a call from within an app or launch an app immediately after the call ends? I know this is possible because some apps in the app store are already doing this.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mithin
  • 961
  • 1
  • 11
  • 37
  • Use webview to make call. Its properly explained in this question: http://stackoverflow.com/questions/5317783/return-to-app-behavior-after-phone-call-different-in-native-code-than-uiwebview – Bushra Shahid Sep 26 '11 at 08:27

4 Answers4

6

I got this code from Apple site and it works perfectly:

-(IBAction) dialNumber:(id)sender{

NSString *aPhoneNo = [@"tel://" stringByAppendingString:[itsPhoneNoArray objectAtIndex:[sender tag]]] ; NSURL *url= [NSURL URLWithString:aPhoneNo];
 NSURL  *url= [NSURL URLWithString:aPhoneNo];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];

if ([osVersion floatValue] >= 3.1) { 
UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; 
[webview loadRequest:[NSURLRequest requestWithURL:url]]; 
webview.hidden = YES; 
// Assume we are in a view controller and have access to self.view 
[self.view addSubview:webview]; 
[webview release]; 
} else { 
// On 3.0 and below, dial as usual 
[[UIApplication sharedApplication] openURL: url];
}


}
Dilip Rajkumar
  • 7,006
  • 6
  • 60
  • 76
3

I think there are two parts to this

  1. The application is already running, and the user receives a prompt indicating a phone call is coming in, and asked to accept or reject
  2. The user receives a phone call, but the application is not running

In the first case, your UIApplicationDelegate will receive messages application:willChangeStatusBarFrame:, application:didChangeStatusBarFrame:, applicationWillResignActive:, and applicationDidBecomeActive: all potentially multiple times all depending on if the user elects to answer the call or not, and possibly applicationWillTerminate: if they choose to leave your application or not. You can also observe these events using the NSNotificationCenter from a class that is not registered as the application delegate, see the "Notifications" section of the UIApplication class reference for details.

In the second case, I do not know there is away with the official SDK to launch your application when a phone call ends. Could you provide a list of the applications that do this?

EDIT:

I think I understand what you mean now. You should follow the advice from @jessecurry, the openURL on UIApplication with a tel: protocol will make a phone call. As to their claim of "doing the impossible" and not quitting the app when the phone call is made, I'm not sure how they did it because I didn't write it. They could be using an external VOIP service like Skype, or simply loading the tel: URL inside an invisible websheet. Neither of which I can comment on because I haven't tried it.

slf
  • 22,595
  • 11
  • 77
  • 101
  • Here are couple of apps that are doing it 1. Baby Monitor & Alarm (http://www.isarson.com/en/baby-monitor-alarm-iphone). One of their recent tweets - "Baby Monitor & Alarm now with unlimited numbers of alarms. Yes, we did impossible, our app is not exited, when phone call is performed! — 4 weeks 22 hours ago" 2. Wakeup Call Alarm – Mithin Feb 23 '10 at 10:04
  • Remember that with 3.x+ if you do use `openURL` users will get a prompt now. In 2.x it would just dial – slf Feb 23 '10 at 21:21
1

It is done by using telprompt instead of tel. please look at the following code

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt:18004912200"]];

Sandeep
  • 1,094
  • 9
  • 6
0

if you'd like to make a call from within your app you can use a tel: url.

Here is a method that takes a telephone number as a string and initiates a call.

- (void)dialNumber: (NSString*)telNumber
{
    // fix telNumber NSString
    NSArray* telComponents = [telNumber componentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
    telNumber = [telComponents componentsJoinedByString: @""];

    NSString* urlString = [NSString stringWithFormat: @"tel:%@", telNumber];
    NSURL* telURL = [NSURL URLWithString: urlString];
    //NSLog( @"Attempting to dial %@ with urlString: %@ and URL: %@", telNumber, urlString, telURL );

    if ( [[UIApplication sharedApplication] canOpenURL: telURL] )
    {
        [[UIApplication sharedApplication] openURL: telURL];
    }
    else
    {
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle: NSLocalizedString( @"Dialer Error", @"" ) 
                                                        message: [NSString stringWithFormat: NSLocalizedString( @"There was a problem dialing %@.", @"" ), telNumber] 
                                                       delegate: nil 
                                              cancelButtonTitle: NSLocalizedString( @"OK", @"" ) 
                                              otherButtonTitles: nil];
        [alert show];
        [alert release];
    }
}
jessecurry
  • 22,068
  • 8
  • 52
  • 44