Question

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.

Was it helpful?

Solution

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];
}


}

OTHER TIPS

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.

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

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

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];
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top