Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

application openURL in Swift

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.

like image 796
BassetMan Avatar asked Oct 03 '14 11:10

BassetMan


1 Answers

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

like image 156
Muhammad Asyraf Avatar answered Sep 17 '22 18:09

Muhammad Asyraf