7

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 crashes immediately when I have the method implemented.

The depreciated handleOpenURL works, but not OpenURL?

At the moment I have no code in the implementation, and am just returning true.

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool {
    return true
}

The crash says Thread 1: EXC_BAD_ACCESS (code-1, address-0x0)

I don't really want to have to use the deprecated method.

David Berry
  • 40,941
  • 12
  • 84
  • 95
BassetMan
  • 461
  • 6
  • 13
  • You might try making the `sourceApplication` parameter an implicitly unwrapped optional as this is typical of signature mismatch between method signatures and attempting to pass nil into a non-optional parameter. Of course it's also indicative of a couple of thousand other possible errors, since it just indicates `abort()` was called... Could also be that the `annotation` parameter needs to be implicitly unwrapped instead of explicitly. Thinking about it more, that's actually more likely. – David Berry Oct 03 '14 at 16:04
  • Thanks David, you were correct it was actually the sourceApplication parameter. If you want to add this as an answer I will accept it. Thanks again – BassetMan Oct 04 '14 at 14:59

3 Answers3

6

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

Muhammad Asyraf
  • 1,748
  • 15
  • 20
3

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.

David Berry
  • 40,941
  • 12
  • 84
  • 95
1

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
    }
Andy G
  • 129
  • 2
  • 4