我阅读了所有可以找到的帖子,并且在点击粘贴到iOS上的Notes应用程序中的动态链接后第一次启动应用程序时仍然会收到一个nil URL。其实我跟着视频:
https://www.youtube.com/watch?v=sFPo296OQqk
Universal Links可以通过application(_:continue:restorationHandler:)
正常工作。
但是,在通过application(_:open:options:)
(以前为application:openURL:options:
)时,该网址为<my-scheme-name>://google/link/?is_weak_match=1
。无论我如何配置我的项目/应用程序,URL始终为零。此外,无论在安装应用程序之前是否点击了动态链接,都会在每次首次启动应用时调用application(_:open:options:)
。这是预期的吗?
配置:
拨打didFinishLaunchingWithOptions
[FIROptions defaultOptions].deepLinkURLScheme = CUSTOM_URL_SCHEME;
[FIRApp configure];
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks dynamicLinkFromCustomSchemeURL:url];
if (dynamicLink) {
// Handle the deep link. For example, show the deep-linked content or
// apply a promotional offer to the user's account.
// [START_EXCLUDE]
// In this sample, we just open an alert.
NSString *message = [self generateDynamicLinkMessage:dynamicLink];
[self showDeepLinkAlertViewWithMessage:message];
// [END_EXCLUDE]
return YES;
}
// [START_EXCLUDE silent]
// Show the deep link that the app was called with.
[self showDeepLinkAlertViewWithMessage:[NSString stringWithFormat:@"openURL:\n%@", url]];
// [END_EXCLUDE]
return NO;
}
// [END openurl]
// [START continueuseractivity]
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler
{
// [START_EXCLUDE silent]
NSLog(@"%@", userActivity.webpageURL);
__weak AppDelegate *weakSelf = self;
// [END_EXCLUDE]
BOOL handled = [[FIRDynamicLinks dynamicLinks]
handleUniversalLink:userActivity.webpageURL
completion:^(FIRDynamicLink * _Nullable dynamicLink,
NSError * _Nullable error) {
// [START_EXCLUDE]
AppDelegate *strongSelf = weakSelf;
NSString *message = [strongSelf generateDynamicLinkMessage:dynamicLink];
[strongSelf showDeepLinkAlertViewWithMessage:message];
// [END_EXCLUDE]
}];
// [START_EXCLUDE silent]
if (!handled) {
// Show the deep link URL from userActivity.
NSString *message =
[NSString stringWithFormat:@"continueUserActivity webPageURL:\n%@", userActivity.webpageURL];
[self showDeepLinkAlertViewWithMessage:message];
}
// [END_EXCLUDE]
return handled;
}
// [END continueuseractivity]
- (NSString *)generateDynamicLinkMessage:(FIRDynamicLink *)dynamicLink {
NSString *matchConfidence;
if (dynamicLink.matchConfidence == FIRDynamicLinkMatchConfidenceStrong) {
matchConfidence = @"strong";
} else {
matchConfidence = @"weak";
}
NSString *msg = [NSString stringWithFormat:@"App URL: %@\n"
@"Match Confidence: %@\n",
dynamicLink.url, matchConfidence];
return msg;
}
- (void)showDeepLinkAlertViewWithMessage:(NSString *)message {
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
NSLog(@"OK"); }];
UIAlertController *alertController =
[UIAlertController alertControllerWithTitle:@"Deep-link Data"
message:message
preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:okAction];
[self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
}
设定:
答案 0 :(得分:0)
请尝试连接到手机和WiFi并重复实验。此外,连接到不同的WiFi网络可能有助于找出问题。如果您的WiFi具有少量面向公众的IP地址,则检索未决动态链接可能会失败。另请参阅此回答中的建议Firebase Dynamic Links not survive installation
如果这不起作用,我建议您使用Firebase打开支持服务单。
关于您收到的链接<my-scheme-name>://google/link/?is_weak_match=1
:此链接由FDL iOS SDK发送,用于通知待处理的动态链接不可用的事件。只有在首次启动应用程序后,您才会收到此链接。如果我们发现待处理的动态链接,我们将通过该动态链接。