Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

swift - Support URL schemes in macOS application

There are several (old) questions on this subject, but none of the solutions worked for me, so here's the question: How to add a URL scheme, so it will be possible to open my app via the browser?

I did the following:

  1. Added the required info to the info.plist:

enter image description here

  1. I Added those functions:
func applicationWillFinishLaunching(_ notification: Notification) {
     NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(handleEvent(_:with:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}

@objc func handleEvent(_ event: NSAppleEventDescriptor, with replyEvent: NSAppleEventDescriptor) {
     NSLog("at handleEvent")
}
  1. I also tried to add this function:
func application(_ application: NSApplication, open urls: [URL]) {
    for url in urls {
        NSLog("url:(url)")
    }
}

None of the above worked. I have a webpage that redirect with MyAppLogin://test but nothing happens. It doesn't matter if the app is open or closed (I want it to work in both cases)

Any idea what's the problem here?

Edit: Two more details:

  1. The app is sandboxed
  2. I'm running it via Xcode (so the installation is not at the 'Applications' folder)
question from:https://stackoverflow.com/questions/65890597/support-url-schemes-in-macos-application

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...