How to handle with a default URL scheme

前端 未结 5 450
花落未央
花落未央 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:27

    All credits should go to weichsel and kch

    I'm just adding swift(2.2/3.0) code for your convenience

    func applicationWillFinishLaunching(_ notification: Notification) {
        NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(self.handleGetURL(event:reply:)), forEventClass: UInt32(kInternetEventClass), andEventID: UInt32(kAEGetURL) )
    }
    
    func handleGetURL(event: NSAppleEventDescriptor, reply:NSAppleEventDescriptor) {
        if let urlString = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue {
            print("got urlString \(urlString)")
        }
    }
    

提交回复
热议问题