iOS10之前,我們進行判斷手機是否裝有應有并跳轉代碼一般是這麼樣的
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}else{
[self p_goAdsPageWithWebsite:WOHAIBAO_DOWNLOAD_URL];// 跳轉
}
但是很不幸,經真機測試
[[UIApplication sharedApplication] canOpenURL:url]
在iOS10上失效了,
在iOS10上新出了一個api
文檔解釋是這樣的
// Options are specified in the section below for openURL options. An empty options dictionary will result in the same
// behavior as the older openURL call, aside from the fact that this is asynchronous and calls the completion handler rather
// than returning a result.
// The completion handler is called on the main queue.
options這一塊傳遞用來做什麼暫時不知道,但是如果傳空字典就跟以前openUrl作用一樣,并且有一個在主線程的異步回調block
是以在iOS10上調用openUrl應該使用
if (isiOS10) {
[[UIApplication sharedApplication] openURL:url options:@{UIApplicationOpenURLOptionsOpenInPlaceKey:@"1"} completionHandler:^(BOOL success) {
// 回調
if (!success) {
[self p_goAdsPageWithWebsite:WOHAIBAO_DOWNLOAD_URL];
}
}];
}else{
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}else{
[self p_goAdsPageWithWebsite:WOHAIBAO_DOWNLOAD_URL];
}
}
that’s all