SteveS
SteveS

Reputation: 536

iOS canOpenURL fails for phone dialing

Try as I might I cannot get a simple app to dial a number.

I hooked a button action to this function:

@IBAction func wackAMole(sender: AnyObject) {
    var phoneNumber = "tel://555-555-5555"
    var url = NSURL(fileURLWithPath: phoneNumber)
    var sharedApplication = UIApplication.sharedApplication()
    if (sharedApplication.canOpenURL(url)) {
        sharedApplication.openURL(url)
    }
}

I have also added "telephony" to Info.plist as a "Required device capabilities" Still to no avail. When running under the debugger on an iPhone 5 canOpenURL() returns false.

Even if I change phoneNumber to "https://google.com", canOpenURL() will return false.

Any ideas where to look next?

Upvotes: 0

Views: 465

Answers (1)

Paulw11
Paulw11

Reputation: 114855

You aren't creating a URL for a local file system entry, so you shouldn't use fileURLwithPath. You should use URLWithString -

var url = NSURL.URLWithString(phoneNumber)

Upvotes: 4

Related Questions