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. And I didn't make this page. I want to remove this.
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];
}];
}