TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Trying to use deeplink URL to launch app

Forums > SwiftUI

Hi folks, I'd appriciate any pointers here. I'm trying to learn how to use deeplinks to open and control an app. So i've setup the schema in Xcode and indeed my app opens when I specify a URL in Safari or via

xcrun simctl openurl booted myApp://

So far so good.

But I can't seem to interogate the URL in the app. If I run the code below I never see the URL printed in the console, I simply see

About to evaluate URL
Launch Options: nil
Evaluate URL done

So clearly the URL is not being passed through.

Any ideas?

import SwiftUI

@main
struct MyApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    var body: some Scene {
        WindowGroup {
        }
    }
}

class AppDelegate: NSObject, UIApplicationDelegate {
    var deepLinkURL: URL?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {

        print("About to evaluate URL")
        print("Launch Options: \(String(describing: launchOptions))")
        if let url = launchOptions?[.url] as? URL {
            deepLinkURL = url
            print("Deep Link URL: \(url)")
        }
        print("Evaluate URL done")

        return true
    }
}

1      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.