0

I am making an as3 AIR app. I want to put phone numbers in the application. On an iPhone, when the user clicks the "phone number" button it calls tel similar to this:

str = "tel:1-415-555-1212"; 
var urlReq:URLReq = new URLRequest(str); 
navigateToURL(urlReq);

This puts the phone number in the users native dialer (on iOS it actually dials it for you and sends also). However, on iPad it does nothing. I want to first check if tel is supported. If it is, do normally. If it is not, show a popup with the phone number. I want to do it pretty much exactly the same for android phones and tablets as well.

Kara
  • 6,115
  • 16
  • 50
  • 57
Fans
  • 79
  • 1
  • 9

1 Answers1

1

As far as I know, there is no way to do this in AIR alone. In Objective-C, you can do this with a method called canOpenURL. Fairly trivial. There is no AIR equivalent.

So you have two options:

  1. Create/find an ANE that gives access to this. I think distriqt offers one that does it, though they are not cheap. This would be a fairly easy one to create, though, so it might be worth doing on your own.
  2. You create a method that can distinguish iPad from iPhone. You can do this a variety of ways (subject for another question). I do not recommend this method, however. This relies on an iPad not being able to make phone calls. There is a possibility that such an app exists that allows you to do that through the tel URI. It is unlikely, given Apple's general practices, but possible.

Edit: I ended up needing this feature myself yesterday, so I hunted down an ANE that provides the functionality. Huge thanks to StickSports for releasing all of their ANEs. https://github.com/StickSports/ANE-Can-Open-URL

Example usage:

public static function shareTwitter( url:String, message:String = null ):void {
    var msg:String = ( message ? message : "" ) + " " + url;
    var nurl:String = "twitter://post?message=" + msg;
    var web:String = "https://twitter.com/intent/tweet?text=" + message + "&url=" + url;

    if ( CanOpenUrl.canOpen( nurl ) ) {
        navigateToURL( new URLRequest( nurl ) );
    }
    else {
        navigateToURL( new URLRequest( web ) );
    }
}
Community
  • 1
  • 1
Josh
  • 8,079
  • 3
  • 24
  • 49
  • Thanks. I think we are going to end up always showing the popups. This way when the text is clicked it will do something on phones and doing nothing on tablets which will be ok because the user can see the information. – Fans Dec 11 '13 at 06:28
  • Yeah, that's how I've ended up doing it in the past as well. On iOS, it auto-dials as well, which is annoying. So the popup gives them the option to prevent that auto-dial – Josh Dec 11 '13 at 15:53
  • @Fans I just edited my answer with a link to ANE I found yesterday when I needed this feature. Hopefully it helps – Josh Dec 13 '13 at 18:33