Reputation: 869
I'm trying to implement Universal Links in my app. I read a lot of tutorials and followed this one to the letter: How to support Universal Links in iOS App and setup server for it?
When I click a universal link my app successfully opens but application:continueUserActivity:restorationHandler
in my AppDelegate.m file isn't called so I can't direct to a specific page in the app.
My apple-app-site-association
file is on https and for paths I put [ "*", "/" ]
. I triple-checked app prefix and ID, confirmed AssociatedDomains is enabled both on the developer website and in my target. In the Associated Domains section I put my root domain as well as a second entry prepended with *. to handle all possible subdomains. I am testing on a real device, not on the simulator.
-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
ALog(@"Did I get here?");
}
Can anyone provide advice as to what I should be looking at to figure out why application:continueUserActivity:restorationHandler
isn't being called?
Update:
I used Apple's validation tool https://search.developer.apple.com/appsearch-validation-tool and it gave this result:
Link to Application
Action required
Could not extract required information for Universal Links. Learn how to implement the recommended Universal Links.
Error no apps with domain entitlements The entitlement data used to verify deep link dual authentication is from the current released version of your app. This data may take 48 hours to update.
I don't know if that has anything to do with my problem. I wouldn't think so, because I need to test my app to make sure I have Universal Links implemented properly before actually releasing the update.
Upvotes: 10
Views: 3779
Reputation: 101
I was struggling with this issue in SwiftUI in iOS 17 - none of the AppDelegate/SceneDelegate "url handling" callbacks worked. Solution that worked:
struct MyApp: App {
var body: some Scene {
WindowGroup {
RootView()
.onOpenURL { incomingURL in
print("URL: \(incomingURL.absoluteString)")
}
}
}
}
But I believe such a handler can be attached to any view, while that view is present in the hierarchy.
Upvotes: 0
Reputation: 11
Nowadays the problem could be that the message is not sent to AppDelegate, but to its successor: scene delegate. So use then this method instead:
UIWindowSceneDelegate::scene(_ scene: UIScene, continue userActivity: NSUserActivity)
Upvotes: 1
Reputation: 591
If Google Analytics or some Firebase features is used in the app, it may be caused by method swizzling. Adding the following method in application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)
solves the issue for me. I think disabling method swizzling will work too.
private func swizzleSelectors() {
let aClass: AnyClass! = object_getClass(UIApplication.shared.delegate)
let originalMethod = class_getInstanceMethod(aClass, #selector(self.application(_:continue:restorationHandler:)))
let swizzledMethod = class_getInstanceMethod(aClass, #selector(UIApplication.shared.delegate!.application(_:continue:restorationHandler:)))
if let originalMethod = originalMethod, let swizzledMethod = swizzledMethod {
method_exchangeImplementations(originalMethod, swizzledMethod)
}
}
Upvotes: 1