8

I am trying to initiate a call from my iphone app,and I did it the following way..

-(IBAction) call:(id)sender
{

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Call Besito" message:@"\n\n\n"
                                                   delegate:self cancelButtonTitle:@"Cancel"  otherButtonTitles:@"Submit", nil];


    [alert show];
    [alert release];
}

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != [alertView cancelButtonIndex])
    {
      NSString *phone_number = @"0911234567"; // assing dynamically from your code
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString    stringWithFormat:@"tel:%@", phone_number]]]; 
         NSString *phone_number = @"09008934848";
        NSString *phoneStr = [[NSString alloc] initWithFormat:@"tel:%@",phone_number];
        NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr];
        [[UIApplication sharedApplication] openURL:phoneURL];
        [phoneURL release];
        [phoneStr release];
    }
}

by the above code..I am able to successfully make a call..but when I end a call,I'm not able to return to my app

So, I want to know how to achieve,that..also please tell me how we can initiate a call using webview...

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ranjit
  • 4,576
  • 11
  • 62
  • 121
  • This question answers your question in detail. Simply use a uiwebview to place call instead of openURL: 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:37

6 Answers6

18

This is my code :

NSURL *url = [NSURL URLWithString:@"telprompt://123-4567-890"]; 
[[UIApplication  sharedApplication] openURL:url]; 

Use this so that after call end it will return to app.

1
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:@"tel:+9196815*****"];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];

Please try this it will definitely let you Back to Your App.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Sambit K.
  • 55
  • 6
0

following code will not return to your app [no alertview will show before make call]

UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];

following code will return to your app "alertview will show before make call"

UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@", phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
aksh1t
  • 5,410
  • 1
  • 37
  • 55
Mani
  • 305
  • 2
  • 9
0
NSString *phoneNumber =  // dynamically assigned
NSString *phoneURLString = [NSString stringWithFormat:@"tel:%@", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];
-1

You can also use webview, this is my code :

NSURL *url = [NSURL URLWithString:@"tel://123-4567-890"];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(50, 50, 150, 100)];
[self.view addSubview:btn];
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(50, 50, 150, 100)];
webview.alpha = 0.0;        
[webview loadRequest:[NSURLRequest requestWithURL:url]];
// Assume we are in a view controller and have access to self.view
[self.view insertSubview:webview belowSubview:btn];
[webview release];
[btn release];
-4

It's not possible to return back to the app after ending a call because it's an app.

Lokus001
  • 159
  • 1
  • 5
  • hi lokus,but many say its possible through by using webview..to make a call – Ranjit Aug 18 '11 at 09:18
  • Are you talking about this post http://stackoverflow.com/questions/3145418/placing-a-call-programmatically-on-iphone-and-return-to-the-same-app-after-hangup ? – Lokus001 Aug 18 '11 at 09:23
  • ya,,,lokus and laso this http://stackoverflow.com/questions/5317783/return-to-app-behavior-after-phone-call-different-in-native-code-than-uiwebview – Ranjit Aug 18 '11 at 09:25
  • you can return to application using `telprompt` instead of `tel` – atastrophic Jul 18 '12 at 05:29