I'm working on an app that needs to get an authorization token from an external provider. So, I need a custom URL scheme for the redirection callback.
The redirection callback is: chirper://success
.
I registered the URL Scheme in my Info.plist
:
I also added the following method in my AppDelegate.swift
:
func handleGetURLEvent(event: NSAppleEventDescriptor?, replyEvent: NSAppleEventDescriptor?) {
if let aeEventDescriptor = event?.paramDescriptor(forKeyword: AEKeyword(keyDirectObject)) {
if let urlStr = aeEventDescriptor.stringValue {
let url = URL(string: urlStr)
print(url)
// do something with the URL
}
}
}
But when I open the redirection callback URL with Safari, this is what I get:
Safari can't open this URL because macOS doesn't recognize URLs that start with
chirper:
Try to "Clean Build Folder" and rebuild. Did help for me. Looks like this is required in some cases.
According to the answer to this question, the problem is the inclusion of ://
in the callback URL. If you remove those, the URL should be opened. I found this was correct on macOS 10.15.5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With