项目里的H5需要打开跳转到支付宝/微信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));
这次使用的时候发现已经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(@"支付宝付款页面跳转状态:%@", success);
if(!success){
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示"
message:@"未检测到支付宝客户端,请安装后重试。"
delegate:self
cancelButtonTitle:@"立即安装"
otherButtonTitles:nil];
[alert show];
}
}];
跳转正常,检测状态正常,但是!!APP不保活了!,从支付宝回来之后,APP会重新加载!!那用户千辛万苦进入到的H5页面,还需要重新走一遍。。
迫于无奈,改回老方法
if([[UIApplication sharedApplication] canOpenURL:url]){
[[UIApplication sharedApplication] openURL:url];
}
以上😮💨