skip to Main Content

I’m trying to integrate Shopify SDK on a SwiftUI project and I’m having some troubles with the authentication flow.

The code provided on the documentation is pretty straight forward:

    func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        spotifyConnection.sessionManager.application(application, open: url, options: options)
        return true
    }

with SwiftUI though this delegate method is never called so I’m trying to use openUrl

    var body: some Scene {
        WindowGroup {
            MenuView()
            .onOpenURL { (url) in
                spotifyConnection.sessionManager.application(??, open: url, options: ??)
            }
        }
    }

Question is how do I access the parameters application and options from here?

2

Answers


  1. You need an UIApplicationDelegateAdaptor

    @main
    struct MyApp: App {
        @UIApplicationDelegateAdaptor private var appDelegate: MyAppDelegate
    
        var body: some Scene { ... }
    }
    
    class MyAppDelegate: NSObject, UIApplicationDelegate, ObservableObject {
        func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
            spotifyConnection.sessionManager.application(application, open: url, options: options)
            return true
        }
    }
    
    Login or Signup to reply.
  2. I am also having the same issue, for Spotify SDK particularly, I tried passing in UIApplication.shared and an empty options dictionary, which seems to work. I also tried examining the options dictionary when I use a UIKit AppDelegate lifecycle. It shows it’s returning openInPlace to be false in the options dictionary in the Spotify url callback.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search