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 Optimize your app’s startup time, binary size, and overall performance using Emerge’s advanced app optimization and monitoring tools. Reliably measure app size, speed up your app's startup time with Emerge's Launch Booster, and much more. Emerge is actively used by many of the top mobile development teams in the world.

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.