Objective c 如何使用URL打开我的Swift应用程序并传递数据?

Objective c 如何使用URL打开我的Swift应用程序并传递数据?,objective-c,cocoa,url,swift,uri,Objective C,Cocoa,Url,Swift,Uri,我试图让我的应用程序能够捕获启动它的url,并解析传递的值 下面是如何在ObjC中完成的 - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent { [event paramDescriptorForKeyword:keyDirectObject] ; NSString *urlStr = [[event paramDes

我试图让我的应用程序能够捕获启动它的url,并解析传递的值

下面是如何在ObjC中完成的

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
  [event paramDescriptorForKeyword:keyDirectObject] ;

   NSString *urlStr = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
     // Now you can parse the URL and perform whatever action is needed
   NSLog(@"URL: %@", urlStr);
}
到目前为止我所知道的是

func handleGetURLEvent(event: NSAppleEventDescriptor?, replyEvent: NSAppleEventDescriptor?) {

}

我想这就是你需要的

func handleGetURLEvent(event: NSAppleEventDescriptor?, replyEvent: NSAppleEventDescriptor?) {
    if let aeEventDescriptor = event?.paramDescriptorForKeyword(AEKeyword(keyDirectObject)) {
        let urlStr = aeEventDescriptor.stringValue
        println(urlStr)
    }
}

在网上搜寻了几天后。。。我找到了这个解决办法

func applicationWillFinishLaunching(notification: NSNotification?) {

    // -- launch the app with url
    NSAppleEventManager.sharedAppleEventManager().setEventHandler(self, andSelector: Selector("handleGetURLEvent:withReplyEvent:"), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}

func handleGetURLEvent(event: NSAppleEventDescriptor!, withReplyEvent: NSAppleEventDescriptor!) {
    let urlPassed = NSURL(string: event.paramDescriptorForKeyword(AEKeyword(keyDirectObject))!.stringValue!)
    println(urlPassed)
}
我的代码中有两个问题。首先,我的选择器与获取url的函数名(handleGetURLEvent)不匹配。第二个问题是找到展开选项时感叹号的正确位置


如果你有同样的问题,希望这能帮助你

我得到了一个错误:“Int”不能转换为“AEKeyword”,我得到了同样的错误@“布莱恩彼得斯,你有没有弄明白这一点?希望它现在对你来说能正常工作,@CliftonLabrum”