4

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];
    }];
}
Nikita Lyu
  • 67
  • 2
  • 8
  • Please see my answer here: https://stackoverflow.com/questions/44252185/firebase-dynamic-link-always-goes-to-app-store-url-even-if-the-app-is-installed/59331408#59331408 – Joshua Wolff Dec 14 '19 at 00:46

1 Answers1

8

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];
Oleksiy Ivanov
  • 2,454
  • 15
  • 21
  • thanks for replying! But it's still not working :( However, I delete "com." from "ibi" parameter in the original link which is written in my ProductView.m, and it hide the app preview page! But come out another problem that if user did not installed app, it won't link to app store.... – Nikita Lyu Dec 11 '17 at 10:41
  • Missed one point in your code, edited answer. You need to use FIRDynamicLinkIOSParameters to fill out iOS related parameters. See https://firebase.google.com/docs/dynamic-links/ios/create how to create links and provide parameters on iOS. – Oleksiy Ivanov Dec 11 '17 at 21:25
  • Thank u so much. I change my originalLink to "https://levooya.com/product?product_id=%u" and it directs to my app perfectly if the app has been installed! But I still can't link to app store when the app did not installed. I think maybe is the parameter problem. – Nikita Lyu Dec 12 '17 at 06:28
  • Did you specified FIRDynamicLinkIOSParameters? FIRDynamicLinkIOSParameters.appStoreID required for AppStore navigation to happens. – Oleksiy Ivanov Dec 12 '17 at 15:54
  • I tested few days and had a question: Is that a way to set preview page only shows when app uninstalled, but hide when installed? I have been tried to specify FIRDynamicLinkIOSParameters, but when I add it , dynamic link always showed me preview page first. – Nikita Lyu Dec 20 '17 at 03:28
  • You should not see App preview page when App is already installed. Several unfriendly Apps will be exception to this, like Twitter, Facebook and maybe couple more. Also check interaction graph on link's debug page, this will show when app preview page expected to be shown. To get to debug page append ?d=1 to the end of your dynamic link. – Oleksiy Ivanov Dec 20 '17 at 05:37