在MacOS上无法识别CallBackURL

时间:2020-05-02 18:57:05

标签: swift macos twitter callbackurl

我正在尝试通过Matt Donnelly(https://github.com/mattdonnelly/Swifter)的SwifterMac功能在MacOS中启用Twitter。

我已经在我的AppDelegate代码中实现了以下内容:

        let swifter = Swifter(consumerKey: "MYVALIDKEY", consumerSecret: "MYVALIDSECRET")

        override init(){
            super.init()

            let callbackUrl = URL(string: "registeredcallback://success")!
            swifter.authorize(withCallback: callbackUrl, success: { _, _ in
                self.swifter.postTweet(status: "test",success: { status in
                    print("successfully tweeted! \(status.description)")
                }, failure: { error in
                    print("error tweeting! \(error)")
                })
            }, failure: failureHandler)
        }

        func applicationDidFinishLaunching(_ notification: Notification) {
            NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(AppDelegate.handleEvent(_:withReplyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
            LSSetDefaultHandlerForURLScheme("registeredcallback" as CFString, Bundle.main.bundleIdentifier! as CFString)
            let contentView = ContentView()
            swifter.postTweet(status: "test",success: { status in
                      print("successfully tweeted! \(status.description)")
                  }, failure: { error in
                      print("error tweeting! \(error)")
                  }
            )
            // Create the window and set the content view.
            window = NSWindow(
                contentRect: NSRect(x: 0, y: 0, width: 400, height: 640 ),
                styleMask: [.titled, .closable, .miniaturizable, .fullSizeContentView],
                backing: .buffered, defer: false)
            window.center()
            window.setFrameAutosaveName("Main Window")
            window.contentView = NSHostingView(rootView: contentView)
            window.makeKeyAndOrderFront(nil)
        }

        @objc func handleEvent(_ event: NSAppleEventDescriptor!, withReplyEvent: NSAppleEventDescriptor!) {
            guard let callbackUrl = URL(string: "registeredcallback://success") else { return }
            guard let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue else { return }
            guard let url = URL(string: urlString) else { return }
            Swifter.handleOpenURL(url, callbackURL: callbackUrl)
        }
    }

当我启动该应用程序时,Safari会通过有效的Twitter身份验证屏幕提示我,但是当我单击“授权”时,会收到消息

Safari can't open "registeredcallback://success?oauth_token=VALIDTOKEN&oautho_verifier=ANOTHERVALIDVALUE" because macOS doesn't recognize Interest addresses starting with "registeredcallback:".

我认为某些内容未正确注册,但是我无法弄清缺少的内容。我已经测试了Swifter随附的示例演示应用程序,并且运行良好。

我已经检查了我的应用沙箱是否设置为允许传入和传出通信(网络)。

0 个答案:

没有答案
相关问题