How to handle with a default URL scheme

前端 未结 5 449
花落未央
花落未央 2020-11-27 13:23

I want to build URI (or URL scheme) support in my app.

I do a LSSetDefaultHandlerForURLScheme() in my + (void)initialize and I setted the s

5条回答
  •  悲哀的现实
    2020-11-27 14:22

    I'm just adding slightly different Swift 4/5 version of the code:

    func applicationWillFinishLaunching(_ notification: Notification) {
        NSAppleEventManager
            .shared()
            .setEventHandler(
                self,
                andSelector: #selector(handleURL(event:reply:)),
                forEventClass: AEEventClass(kInternetEventClass),
                andEventID: AEEventID(kAEGetURL)
            )
    
    }
    
    @objc func handleURL(event: NSAppleEventDescriptor, reply: NSAppleEventDescriptor) {
        if let path = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue?.removingPercentEncoding {
            NSLog("Opened URL: \(path)")
        }
    }
    

提交回复
热议问题