8

Hello All – I am a newbie here ... trying to get my first iOS Swift (Xcode 11.2.1 / Swift 5 / iOS 13.2) app to open via URL and process the URL string. The app opens just fine, but the function (method?) does not appear to be getting called. Here's what I've got:

class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        print("Here I iz ... in the URL responding bit.")
        print(url)
        return true
    }

...

That code is in the AppDelegate.swift file in my project.

My Info.plist for the app

And that is what I have in my Info.plist file.

I launch via Safari both on-device and in the simulator with confirmevent://HelloWorld

As I said ... The app is opening, but I do not see any results from my print statements in the Xcode debug area.

In searching other posts they said that I need to use the "Wait for executable to be launched" to attach Xcode to the app, which I have done and it is indeed attaching. BUT I notice that none of my dozens of print statements that I have scattered about in my app appear when either when opening via "wait for executable to be launched" option.

Any/All help would be appreciated. I've spent over 5 hours scouring the web, but all indications are that is should "just work"

HirsuteJim
  • 529
  • 4
  • 13
  • You don't need to test the cold launch scenario right away. Just debug from Xcode and when your app is launched, _then_ try your URL deep link. – Procrastin8 Dec 11 '19 at 12:21
  • This is a duplicate of https://stackoverflow.com/questions/58624786/applicationopenurloptions-not-called – Hejazi Dec 17 '19 at 11:02

3 Answers3

13

I just found a solution here: application(...continue userActivity...) method not called in ios 13

The trick is to also implement the SceneDelegate.swift functions for Apps with iOS > 13. This function should be called if you open the URL confirmevent://HelloWorld:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    print(URLContexts.debugDescription)
}
emmics
  • 994
  • 1
  • 11
  • 29
-1
WindowGroup {
    SampleView()
        .onOpenURL { url in
            //this url that was opened by your app
        }
    }
}
Andrew_STOP_RU_WAR_IN_UA
  • 9,318
  • 5
  • 65
  • 101
-2

you need to use this function in your appDelegate

func application(_ application: UIApplication, continue userActivity: NSUserActivity,
                     restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        if let incomingURL = userActivity.webpageURL {
           print(incomingURL)
        }
        return false

}
Andres Gomez
  • 458
  • 3
  • 12
  • I added that, thank you. I get the following on the XCode debug area: **As app went into background (to bring up Safari)** 2019-11-27 13:45:56.029375-0500 iOSCreatorSample[22704:4117574] Can't end BackgroundTask: no background task exists with identifier 8 (0x8), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug. **And this when my app came back from background** 2019-11-27 13:46:08.333802-0500 iOSCreatorSample[22704:4117574] [ZOOMCommon] Got a keyboard will hide notification, but keyboard was not even present. – HirsuteJim Nov 27 '19 at 18:47
  • I think that you want to do is a deep link, check this reference (https://medium.com/wolox-driving-innovation/ios-deep-linking-url-scheme-vs-universal-links-50abd3802f97) – Andres Gomez Nov 27 '19 at 18:56
  • I have done both of the above suggestions and there is still no indication that the function/method is even being called. – HirsuteJim Nov 27 '19 at 19:53