WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: Launch app from website link

Forums > macOS

Good morning

Looking for a way to launch my psotal service barcode app from an URL and found this page:

http://www.gietal.net/blog/launch-macos-app-from-url

But this describes an old method using AppDelegate....

Would this have to use now as well this snippet like for push notifications?

@main
struct WedernochApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    var body: some Scene {
        WindowGroup {
            MainView()
        }
    }
}

   

Ah no...there is no AppDelegateAdaptor for macOS.....

Is there another method to add Apple Event receiver for URLScheme?

   

Ah no...there is no AppDelegateAdaptor for macOS.....

There is: NSApplicationDelegateAdaptor | Apple Developer Documentation

   

Right...forgot the good old NextStep workstation I had (o;

So this just works fine:

@main
struct BarcoderApp: App {
    @NSApplicationDelegateAdaptor private var appDelegate: AppDelegate
    var body: some Scene {
        WindowGroup {
            ContentView()

        }
        Settings {
          PreferencesView()
        }
    }
}

class AppDelegate: NSObject, NSApplicationDelegate {
    open func applicationWillFinishLaunching(_ notification: Notification) {
        print("Will Finish Launching")
    }
}

And YESSS...Safari can launch now my Barcoder App ;-)

Now onto parsing URL parameters....

   

Hmm...looks good.....

klingler@Mac-mini-Arbeitszimmer ~ % /Applications/Barcoder.app/Contents/MacOS/Barcoder
Will Finish Launching
["lastname": "klingler", "firstname": "richard"]

   

Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

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.