How to capture the URL used to launch an OS X application via URLScheme in Swift?

前端 未结 2 1072
长情又很酷
长情又很酷 2020-12-18 05:31

I\'ve been trying to replicate the usual way of doing this in Objective-C in Swift for a new swift app I\'m playing around with.

How to do this in Objective-C is wel

相关标签:
2条回答
  • 2020-12-18 05:37

    I found that as of Xcode 8.2 I needed to convert MagerValp's code to the following:

    func applicationWillFinishLaunching(_ notification: Notification) {
        let aem = NSAppleEventManager.shared();
        aem.setEventHandler(self, andSelector: Selector(("handleGetURLEvent:withReplyEvent:")), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
    }
    

    Hope this helps.

    0 讨论(0)
  • 2020-12-18 05:53

    As far as I can tell from the documentation the classes takes the constant and converts it to the proper type:

    func applicationWillFinishLaunching(aNotification: NSNotification?) {
        var appleEventManager:NSAppleEventManager = NSAppleEventManager.sharedAppleEventManager()
        appleEventManager.setEventHandler(self, andSelector: "handleGetURLEvent:withReplyEvent:", forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
    }
    
    0 讨论(0)
提交回复
热议问题