項目里的H5需要打開跳轉(zhuǎn)到支付寶/微信APP挺尾,最近剛在webView里新增該功能站绪。
以前常用的是以下兩個API
- (BOOL)openURL:(NSURL*)url API_DEPRECATED_WITH_REPLACEMENT("openURL:options:completionHandler:", ios(2.0, 10.0)) NS_EXTENSION_UNAVAILABLE_IOS("");
- (BOOL)canOpenURL:(NSURL *)url API_AVAILABLE(ios(3.0));
這次使用的時候發(fā)現(xiàn)已經(jīng)deprecated了,所以用了推薦的新方法
// 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.
- (void)openURL:(NSURL*)url options:(NSDictionary<UIApplicationOpenExternalURLOptionsKey, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion API_AVAILABLE(ios(10.0)) NS_EXTENSION_UNAVAILABLE_IOS("");
那么坑魂挂,他就來啦涂召!
以下代碼:
[[UIApplication sharedApplication] openURL:requestURL options:@{@"UIApplicationOpenURLOptionUniversalLinksOnly": @NO} completionHandler:^(BOOL success) {
NSLog(@"支付寶付款頁面跳轉(zhuǎn)狀態(tài):%@", success);
if(!success){
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示"
message:@"未檢測到支付寶客戶端敏沉,請安裝后重試。"
delegate:self
cancelButtonTitle:@"立即安裝"
otherButtonTitles:nil];
[alert show];
}
}];
跳轉(zhuǎn)正常秋泳,檢測狀態(tài)正常攒菠,但是!辖众!APP不焙途矗活了昼弟!奕筐,從支付寶回來之后,APP會重新加載>扰贰笆怠!那用戶千辛萬苦進入到的H5頁面誊爹,還需要重新走一遍。频丘。
迫于無奈,改回老方法
if([[UIApplication sharedApplication] canOpenURL:url]){
[[UIApplication sharedApplication] openURL:url];
}
以上????