Luca
Luca

Reputation: 20919

Make a phone call when click on a phone number String

I have a phone number like this: 025639879. I got it from the database as a String. Now i want to make a Phone call exactly when the user click on that number, i have tried to do like this:

NSString *phoneNumber=[@"tel://"stringByAppendingString:myAppGlobalVariables.telephoneTheme];


NSString *html = [NSString stringWithFormat:@"<html><body>Téléphone:%@</body
</html>",phoneNumber];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

[webView loadHTMLString:html baseURL:nil];  

What i got in my app is this:

Téléphone:tel://025639879

Am i missing something? thanx in advance.

Upvotes: 1

Views: 1064

Answers (1)

vakio
vakio

Reputation: 3177

You can do it in two ways:

  1. skip the tel:// and make your webview recognize phone numbers as links (there will be false positives so be careful with this).
  2. make a <a href="tel://number">number</a> link:

    NSString *html = [NSString stringWithFormat:@"<html><body><p>Téléphone:<a href=\"tel://%@\">%@</a></p></body></html>", myAppGlobalVariables.telephoneTheme, myAppGlobalVariables.telephoneTheme]; [webView loadHTMLString:html baseURL:nil];

Upvotes: 2

Related Questions