tags:

views:

501

answers:

2

Hi,

Is there a way by which we can 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.

Thanks!

+1  A: 

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
+1  A: 

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
Mithin
Remember that with 3.x+ if you do use `openURL` users will get a prompt now. In 2.x it would just dial
slf