问题描述:

I am working off a tutorial that has this line of code:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]];

When the program is compiled in the 3.0 Framework and that line of code is run, nothing happens. However, if the program is build with the 2.0 Framework that line of code causes a popup to display that says:

"Unsupported URL

This URL wasn't loaded:

tel://8004664411"

Can anyone explain why no error is raised in 3.0?

网友答案:

I don't know why you only see errors in 2.0 framwork builds. When using the Xcode Simulator telephone links are always just ignored.

Anyway, it's good practice to let your application check if the tel url scheme is supported before trying to call a phone number using the canOpenURL class method;


NSString *zeURL = @"tel://8004664411";

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:zeURL]]) {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:zeURL]];
} else { 
    //show own error message dialog
}
网友答案:

And, speaking from very recent experience here, you will get your app rejected in the App Store approval process if you don't properly handle hardware which doesn't support the tel://.

I had a button which I put there, the iPod and the Simulator don't crash, but they do nothing. You should detect and remove the button if running on a device which doesn't support it.

I wanted to kick myself for letting that one get by.

相关阅读:
Top