application openURL in Swift

前端 未结 3 770
囚心锁ツ
囚心锁ツ 2021-01-18 13:57

I am having an issue with the Appdelegate method OpenURL.

I have setup my Imported UTI\'s and Document Type. But when opening my app from a mail attachment, the app

相关标签:
3条回答
  • 2021-01-18 14:43

    This is fairly typical of a signature mismatch between the method signatures automatically generated by the Swift compiler and the actual signature. It happens when you try to pass nil from Objective-C into a Swift explicitly unwrapped optional. Change the annotation parameter to be implicitly unwrapped and you should be gtg.

    0 讨论(0)
  • 2021-01-18 14:55

    I have my head blow for a week with this issue.
    My app keep crashing after Login Using Social Media Such as Wechat / LinkedIn.But Facebook and Google Sign in Works Fine.

    I have notice my app will keep crash after confirm sign in on Wechat Apps and will enter foreground.and Getting BAD EXCESS error. I have try to remove my application open url method on AppDelegate and the app wont crash but the action for Social Media Login are not functioning. so I detect that my issue was on the specific method. after search the web I found that im using an deprecated method of ApplicationOpenUrl as reference from https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623073-application

    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        return true
    } // this method is deprecated in iOS 9 https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623073-application
    

    notice that the deprecated version are using annotation:Any which will cause issue if you had bridging to an Obj-c framework such as wechat.
    So what I do was, I swap my code into a the new format

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String
        let annotation = options[UIApplicationOpenURLOptionsKey.annotation]
        let application = app
    
        return true
    }
    

    Hope this help. it will became my reference in feature also. thanks StackOverflow

    0 讨论(0)
  • 2021-01-18 14:55

    Swift 5 version of Muhammad Asyraf's answer:

        func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
            let sourceApplication = options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String
            let annotation = options[UIApplication.OpenURLOptionsKey.annotation]
    
            return true
        }
    
    0 讨论(0)
提交回复
热议问题