0

In kotlin multiplatform with IOS, I am trying to start the app via a link and some parameters:

iosstaging://open?userId=1234

That part works fine. Upon entering the link into safari, the browser asks if I would like to open the app and then proceeds to do so.

My problem is, that I am not receiving the parameters or the URL. I would except that the following function is called when the app starts (passing the URL as a parameter):

func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:] ) -> Bool

At least that is what I am understanding from the docs: Handle incoming URLs

But this is not the case. Instead, the "normal" application function is called:

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

Additionally: launchOptions are always nil.

My staging pinfo looks like this:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>de.myapp.app</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>iosstaging</string>
        </array>
    </dict>
</array>

Have I missed something within the pInfo file? Do I have to declare, besides naming the scheme, that I expect options to be passed?

I do not use any sceneDelegates and the outcome is always the same wether I start the app fresh or it was already running in the background: App starts fine via the link but the parameters (userId) are missing.

Running Kotlin 2.0.21 with Decompose and MVIKotlin

Any help is greatly appreciated

3
  • doesn't launchOptions has info about custom url? Commented Apr 3 at 12:47
  • Good hint. Yeah, I looked at launchOptions but it is always NIL Commented Apr 3 at 14:49
  • @BastiX did you find a solution to this yet? Commented Jul 30 at 10:51

1 Answer 1

0

The kind folks over at Apple helped me figure this out. The key bit of information here is: SwiftUI is inherently scene based.

To get the parameters at launch you need to have a Scene Delegate:

class SceneDelegate: NSObject, UIWindowSceneDelegate {
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
       // Use connectionsOptions
    }
    
    func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        // Use URLContexts
    }
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.