美文网首页
iOS 14 bug

iOS 14 bug

作者: 嘛尼嘛哄 | 来源:发表于2020-09-22 00:06 被阅读0次

1. CanLaunch方法失效(替换默认浏览器)

  • 当设置默认浏览器为Chrome时,UIApplication.shared.canLaunchUrl()方法失败

  • 临时解决方案,使用 try{ UIApplication.shared.openUrl... } catch { }

测试代码如下


import UIKit
import SafariServices

class ViewController: UIViewController, SFSafariViewControllerDelegate {
   

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
//        UIApplication.shared.open(URL(string: "tel://18562562047")!, options: [:]) { (result) in
//            print("打开: \(result)");
//        }
        let result = print(UIApplication.shared.canOpenURL(URL(string: "https://www.baidu.com/")!))
        print(result)
        let safariURL = NSURL(string: "http://stackoverflow.com")!
        let chromeURL = NSURL(string: "googlechrome://stackoverflow.com")!
        let operaURL  = NSURL(string: "opera-http://stackoverflow.com")!

        
        let safariURLResult = UIApplication.shared.canOpenURL(safariURL as URL);
        let chromeURLResult = UIApplication.shared.canOpenURL(chromeURL as URL);
        let operaURLResult = UIApplication.shared.canOpenURL(operaURL as URL);
        
        print("safariURLResult: \(safariURLResult)")
        print("chromeURLResult: \(chromeURLResult)")
        print("operaURLResult: \(operaURLResult)")

        /**
         safariURLResult: false
         chromeURLResult: false
         operaURLResult: false
         */
        
        let safariVC = SFSafariViewController.init(url: URL(string: "https://www.baidu.com/")!, configuration: SFSafariViewController.Configuration.init());
        safariVC.delegate = self

        topViewController(vc: self)?.present(safariVC, animated: true, completion: {
            print("dddd")
        })
        
    }
    
    func topViewController(vc: UIViewController) -> UIViewController? {
        if ( vc.isKind(of: UINavigationController.classForCoder())){
            return (vc as? UINavigationController)?.children.last
        }
        if (self.isKind(of: UITabBarController.classForCoder())) {
            return topViewController(vc: ((vc as! UITabBarController).selectedViewController)!)
        }
        if ((vc.presentedViewController) != nil) {
            return topViewController(vc: vc.presentedViewController!)
        }
        
        return self;
    }
    
 
    func safariViewController(_ controller: SFSafariViewController, activityItemsFor URL: URL, title: String?) -> [UIActivity] {
        
        return []
    }

    
 
    @available(iOS 11.0, *)
    func safariViewController(_ controller: SFSafariViewController, excludedActivityTypesFor URL: URL, title: String?) -> [UIActivity.ActivityType] {
        return []
    }

    
     
      func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
        print( #function, #line, #column, #file)
    }
    func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {
        
    }

 
    @available(iOS 11.0, *)
    func safariViewController(_ controller: SFSafariViewController, initialLoadDidRedirectTo URL: URL) {
        
    }

}

相关文章

网友评论

      本文标题:iOS 14 bug

      本文链接:https://www.haomeiwen.com/subject/wjbvyktx.html