私の質問はthis questionと同じですが、しばらくの間更新されておらず、回答が更新されるように依頼されてからSwiftが大きく変更されました。私がしたいのは、私のココアアプリを開くために使われたURLをキャプチャするだけですが、コードはハンドラ関数で決して実行されません。カスタムURLスキームでアプリケーションを起動すると、Console.appにエラーがスローされます。ここでのエラーは、次のとおりです。URL Schemeを使用してOpen Cocoa App
-[MyApp.AppDelegate handleGetURLEvent:replyEvent:]: unrecognized selector sent to instance 0x60c0000039b0
-[MyApp.AppDelegate handleGetURLEvent:replyEvent:]: unrecognized selector sent to instance 0x60c0000039b0
OSErr AERemoveEventHandler(AEEventClass, AEEventID, AEEventHandlerUPP, Boolean)(spec,phac handler=0x7fff576b7f15 isSys=YES) err=0/noErr
-[MyApp.AppDelegate handleGetURLEvent:replyEvent:]: unrecognized selector sent to instance 0x60c0000039b0
-[MyApp.AppDelegate handleGetURLEvent:replyEvent:]: unrecognized selector sent to instance 0x60c0000039b0
OSErr AERemoveEventHandler(AEEventClass, AEEventID, AEEventHandlerUPP, Boolean)(GURL,GURL handler=0x7fff5661d680 isSys=YES) err=0/noErr
LSExceptions shared instance invalidated for timeout.
そして、私の裸の骨アプリ:
MyAppという名前の新しいココアアプリを作成します。 Info> URL Typesで、Identifierフィールドに自分のアプリケーションのバンドルIDを入力し、URL Schemesフィールドにblue
などを入力します。ビルド
func applicationWillFinishLaunching(_ notification: Notification) {
let appleEventManager: NSAppleEventManager = NSAppleEventManager.shared()
appleEventManager.setEventHandler(self, andSelector: Selector(("handleGetURLEvent:replyEvent:")), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}
func handleGetURLEvent(event: NSAppleEventDescriptor?, replyEvent: NSAppleEventDescriptor?) {
NSLog("heyo!")
}
と私のアプリを実行します。AppDelegateクラスに次の2つの関数を追加します。終了し、アドレスバーにSafariタイプblue://whatever
を入力し、returnキーを押します。アプリケーションが開きますが、NSLogはConsole.appに表示されず、代わりに上記のエラーが表示されます。私はURLを解析する方法に執着することが大好きですが、私はまだその部分に到達することはできません。私はXcode 8.3.3(8E3004b)とSwift 3.1を実行しています。あなたは私と同じ結果を得ていますか?ハンドラ関数を間違って呼び出していますか?
をあなたは正しい罰金先生です!私は、私が参照した質問にあなたの解答にコメントを残します。ありがとう、トン! – wetjosh