当我使用新版本更新我的应用程序时,会调用openURL方法。但是,当我点击动态链接并在此之后进行更新时,不再调用openURL方法。
有人可以解释为什么会这样吗?
这是我想用openURL方法/
做事的代码- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<NSString *, id> *)options {
// Sends the URL to the current authorization flow (if any) which will
// process it if it relates to an authorization response.
if ([_currentAuthorizationFlow resumeAuthorizationFlowWithURL:url]) {
_currentAuthorizationFlow = nil;
return YES;
}
FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];
NSString *userID = [[NSUserDefaults standardUserDefaults] stringForKey:@"xx"];
NSString *firstTimeAppOpened = [[NSUserDefaults standardUserDefaults] stringForKey:@"xxx"];
if (dynamicLink != nil) {
if ([dynamicLink.url.absoluteString length] != 0) {
NSLog(@"App opened with link: %@", dynamicLink);
NSString *snippet = [NSString stringWithFormat:@"URLScheme: Received dynamic firebase link: %@", dynamicLink.url.absoluteString];
NSString *category = @"DYNAMIC_LINK";
NSString *pathFromURL = [dynamicLink.url.absoluteString lastPathComponent];
[SiteConnector sendAuditWithSnippet:snippet inCategory:category];
NSString *firstTimeAppOpened = [[NSUserDefaults standardUserDefaults] stringForKey:@"FirstTimeAppOpened"];
if ([dynamicLink.url.absoluteString rangeOfString:@"murat"].location == NSNotFound) {
[self dynamicLinkBehaviour:pathFromURL second:dynamicLink.url absolutePath:nil];
} else {
if (firstTimeAppOpened == nil) {
[self onboardingDynamicLink:dynamicLink.url.absoluteString];
}
}
}
else {
if (userID == nil && firstTimeAppOpened == nil) {
[self openWelcomeScreen];
}
}
}
NSString *valueToSave = @"yes";
[[NSUserDefaults standardUserDefaults] setObject:valueToSave forKey:@"FirstTimeLoggedIn"];
[[NSUserDefaults standardUserDefaults] synchronize];
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
答案 0 :(得分:0)
openURL
仅在通过URI方案(即fb://
)打开应用时调用。在大多数情况下,Firebase使用通用链接,通用链接打开的应用会触发continue userActivity
协议功能。您可以参考他们的文档获取该代码:
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
guard let dynamicLinks = DynamicLinks.dynamicLinks() else {
return false
}
let handled = dynamicLinks.handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
// ...
}
return handled
}
这是我推荐使用Branch的一个原因,因为他们在一次回调中处理它们,无论它是URI方案还是通用链接。
答案 1 :(得分:-1)
你好@IOSporgrammerIOS请试试这个。
var yourUrl = NSURL(string:"url_String")! if UIApplication.shared.canOpenURL(yourUrl as URL){ UIApplication.shared.openURL(yourUrl as URL) }
目标C
UIApplication *application = [UIApplication sharedApplication]; NSURL *URL = [NSURL URLWithString:@"http://www.google.com"]; [application openURL:URL options:@{} completionHandler:^(BOOL success) { if (success) { NSLog(@"Opened url"); } }];