I'm trying to open my app from a web page using custom schemes. The app is opened but the following method is not called:
func application(_ app: UIApplication, open url: URL, options [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// This is not called
}
My info.plist
looks like the following:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>MyApp</string>
</array>
<key>CFBundleURLName</key>
<string>url here</string>
</dict>
</array>
The project is created with Xcode 11.1, and I'm testing on iOS 13.
Implement scene(_:openURLContexts:)
in your scene delegate.
If the URL launches your app, you will get scene(_:willConnectTo:options:)
instead and it’s in the options
.
Here is the method in SceneDelegate.swift. Swift version For iOS13
@available(iOS 13.0, *)
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let url = URLContexts.first?.url {
// Handle URL
WXApi.handleOpen(url, delegate: AppDelegate.shared)
}
}
With the latest SDK, this does work fine if you are at NOT using SceneDelegate.
If you are using sceneDelegate the the following AppDelegate method is not called and therefore the login cannot be handled.
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let handled = ApplicationDelegate.shared.application(
application,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation])
return handled
}
This is because, this method is (understandably) deferred to the following method in the SceneDelegate:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
...
}
The solution which I can confirm as working for iOS 13 applications implementing a SceneDelegate is:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
return
}
let _ = ApplicationDelegate.shared.application(
UIApplication.shared,
open: url,
sourceApplication: nil,
annotation: [UIApplication.OpenURLOptionsKey.annotation])
}
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