As3 AIR How to Check if tel is Supported by Device?

406 views Asked by At

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.

1

There are 1 answers

3
Josh On

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