メソッド-(BOOL)openURL:(NSURL*)url
の戻り値を読み取ることができます。それがNOの場合、ターゲットアプリケーションがインストールされていないことを意味します。次のコードNAVIGON URLスキームを使用する例を示します:
NSString *stringURL = @"navigon://coordinate/NaviCard/19.084443/47.573305";
NSURL *url = [NSURL URLWithString:stringURL];
if([[UIApplication sharedApplication] openURL:url]) {
NSLog(@"Well done!");
} else {
stringURL = @"https://itunes.apple.com/it/app/navigon-europe/id320279293?mt=8";
url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
}
アップデートスウィフト3
var stringURL = "navigon://coordinate/NaviCard/19.084443/47.573305"
var url = URL.init(string: stringURL)
if !UIApplication.shared.canOpenURL(url!) {
stringURL = "https://itunes.apple.com/it/app/navigon-europe/id320279293?mt=8"
url = URL.init(string: stringURL)
}
if #available(iOS 10.0, *) {
UIApplication.shared.open(url!, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url!)
}
出典
2014-01-09 15:44:29
Zeb