Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Dynamic Link can’t open app directly

According to Firebase document, I create Dynamic Link in Firebase console, then include the Dynamic Links SDK in my app.

Everything is good, but when I click share link (which is my dynamic link) from facebook or messenger, it popps up a page with a open-app button and ask me if I want to open my app or not. enter image description here And I didn't make this page. I want to remove this. enter image description here

But I click the link from Memorandum, it opens my app and go to the right page directly. I want the same way with the share links.

Here is my code, I use Xcode with Objective-c to develop iOS app. Thanks!

Appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{   
    [FIROptions defaultOptions].deepLinkURLScheme = @"com.levooya.LeVooya";
    [FIRApp configure];
    return YES;
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray * _Nullable))restorationHandler{
    NSURL *url = userActivity.webpageURL;
    NSLog(@"continueUserActivity url.absoluteString:%@",url.absoluteString);

    BOOL handled = [[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL completion:^(FIRDynamicLink *dynamicLink, NSError *error){
        if(dynamicLink.url){
            NSLog(@"okokokokokok");
            NSLog(@"dynamicLink.url:%@",dynamicLink.url);

            NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:dynamicLink.url
                                                      resolvingAgainstBaseURL:NO];

            for(NSURLQueryItem *item in urlComponents.queryItems){
                if([item.name isEqualToString:@"product_id"]){
                    NSLog(@"item.value:%@",item.value);
                    NSString *productID = item.value;

                    NSDictionary *urlSchemeDict = [[NSDictionary alloc] init];

                    urlSchemeDict = [NSDictionary dictionaryWithObject:productID forKey:@"product_id"];
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"URLSchemeShowProduct" object:nil userInfo:urlSchemeDict];

                    leData = [LevooyaData getInstance];
                    leData.urlSchemeDict = nil;
                    leData.urlSchemeDict = urlSchemeDict;
                }
            }
        }
    }];
    return YES;
}

ProductView.m

(This is the page which display product in my app, and here is the function I click share button to generate dynamic link.)

- (void)share{
    NSString *originalLink = [NSString stringWithFormat:@"https://pbu3y.app.goo.gl/?link=https://levooya.com/product?product_id=%u&isi=1221262097&ibi=com.levooya.LeVooya&product_id=%u", productID, productID];
    NSURL *link = [NSURL URLWithString:originalLink];
    FIRDynamicLinkComponents *components =
    [FIRDynamicLinkComponents componentsWithLink:link
                                          domain:@"pbu3y.app.goo.gl"];

    FIRDynamicLinkSocialMetaTagParameters *socialParams = [FIRDynamicLinkSocialMetaTagParameters parameters];
    socialParams.title = product.brand;
    socialParams.descriptionText = product.product;
    components.socialMetaTagParameters = socialParams;

    FIRDynamicLinkNavigationInfoParameters *navigationInfoParameters = [FIRDynamicLinkNavigationInfoParameters parameters];
    navigationInfoParameters.forcedRedirectEnabled = 0;
    components.navigationInfoParameters = navigationInfoParameters;

    [components shortenWithCompletion:^(NSURL *_Nullable shortURL,
                                        NSArray *_Nullable warnings,
                                        NSError *_Nullable error) {
        // Handle shortURL or error.
        if (error) {
            NSLog(@"Error generating short link: %@", error.description);
            return;
        }
        shortenURL = shortURL;

        NSString *noteStr = [NSString stringWithFormat:NSLocalizedString(@"Check out %@ %@ on Levooya ! %@", nil), product.brand, product.product, shortenURL];
        UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[noteStr] applicationActivities:nil];
        [self presentViewController:activityVC animated:YES completion:nil];
    }];
}
like image 543
Nikita Lyu Avatar asked Jan 30 '23 01:01

Nikita Lyu


1 Answers

The page you mentioning is App preview page, see https://firebase.google.com/docs/dynamic-links/link-previews .

You can disable this page by specifying a dynamic link parameter efr=1. There is a checkbox when creating link in console to disable this page as well. In your code use navigationInfoParameters.forcedRedirectEnabled = YES;.

Something to keep in mind: If you see App Preview page when your App is already installed on iPhone, this means Universal Links failed to engage. This may happens when dynamic links was pasted to browser address bar. Or tap on link happened inside non-cooperative App (some Apps disallow engagement of Universal Links). Ensure you tested link behavior with App preview disabled and happy with it.

EDIT: Just realized that your deep link is not correct. Instead of

NSString *originalLink = [NSString stringWithFormat:@"https://pbu3y.app.goo.gl/?link=https://levooya.com/product?product_id=%u&isi=1221262097&ibi=com.levooya.LeVooya&product_id=%u", productID, productID];

you should use your deep link, like this:

NSString *originalLink = [NSString stringWithFormat:@"https://levooya.com/product?product_id=%u", productID];
like image 184
Oleksiy Ivanov Avatar answered Feb 04 '23 02:02

Oleksiy Ivanov