6

I have made the changes for firebase integration using link https://firebase.google.com/docs/dynamic-links/ios following are the handling done to handle URL and navigate the user to respective screen. for iOS version below 9.0 the appdelegate's openURL method is called and I am able to get the URL. But for iOS version 9.0 and above I am getting call in app delegate's ContinueUserActivity method and in that I am getting nil value of dynamicLink.url.

I am not able to understand the reason why I am not able to get the Url.

- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray * _Nullable))restorationHandler {
       NSLog(@"Short URl : %@",userActivity.webpageURL);
       __weak AppDelegate *weakSelf = self;
       BOOL handled = [[FIRDynamicLinks dynamicLinks]
                 handleUniversalLink:userActivity.webpageURL
                    completion:^(FIRDynamicLink * _Nullable dynamicLink,
                                 NSError * _Nullable error) {
                         AppDelegate *strongSelf = weakSelf;
                         [strongSelf handleReceivedLink:dynamicLink];
                    }];
return handled;
}
-(void)handleReceivedLink:(FIRDynamicLink*)dynamicLink{
    NSString* urlString = [NSString stringWithFormat:@"%@",dynamicLink.url];
    NSLog(@"Extended URL : %@",urlString);
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • I'm having the same problem. I was able to narrow down to having %20 characters in my custom parameter. For some weird reason, If i replaced it with %2520 it works fine. I think this is a bug. – tperei Nov 11 '16 at 00:54
  • HeavenlyManBR yes its a bug. Which parameter are you replacing ? Can you please elaborate the solution. – Gaurav Shishodia Nov 11 '16 at 06:36
  • For example, in my link I'm providing a custom parameter ```https://domain.com/card?title=[sometitle]```; if I pass more then one word to the title, for example, "Blue Card", and encode it, it will become ```https://domain.com/card?title=Blue%20Card```. The problem is that "handleUniversalLink" will simply not handle the url and won't give an error; if I manually replaced %20 wth %2520, it works. Summarizing, check if you're passing any parameters with a blank space. Again, this is not a solution but just sharing what I found since it might help you debug your problem. – tperei Nov 11 '16 at 06:45
  • Ok but in my case the url does not contain any blank space. – Gaurav Shishodia Nov 11 '16 at 06:50
  • Does the completion return an error or is the block never fired? – tperei Nov 11 '16 at 06:55
  • dynamicLink.url is returning nil in completion. The extended URL which I am printing in NSLog is giving nil. – Gaurav Shishodia Nov 11 '16 at 09:08
  • @HeavenlyManBR can you please share your implementation in continueUserActivity delegate. As its working fine for you but not for me. – Gaurav Shishodia Nov 17 '16 at 07:16
  • have a look at this: http://stackoverflow.com/a/42526447/2898708 – Noor Ali Butt Mar 01 '17 at 08:15

4 Answers4

0

I had the same issue. I was getting callback of restorationHandler but in handleUniversalLink callback dynamiclink and error both were nil. After spending some time I found the issue. My deep link object was containing space between two words.

For Example: My url was like this: https://domainname.com/card?title=Blue%20Card. At first it was not URLEncoded from server side. So, I made it URLEncoded before passing to the Firebase Dynamic Link object. And in my iOS code i had to make below changes:

NSString *linkURL = [NSString stringWithFormat:@"%@",dynamicLink.url];
linkURL = [linkURL stringByRemovingPercentEncoding];

Now, my dynamicLink is not nil and my linkURL string gives me deep link object.

Pratik Shah
  • 563
  • 4
  • 14
0

Try to update Firebase/DynamicLinks. I'd had the same issue and then I run pod update Firebase/DynamicLinks. Now pod Firebase/DynamicLinks is 6.21.0 version and DynamicLink object has url value.

Lana
  • 11
  • 1
0

After checking all the blogs and posted this issue on firebase, I didn't find any solution for this but I came up with this concrete solution and it will work definitely


here: dynamicLinkURL is your main dynamic link and shortHandURL is your deeplink URL which is associated with your dynamic link. I hope the below snippet will help you.


func dynamicLinkhandler(_ dynamicLinkURL: URL, onCompletion: @escaping(_ success: Bool) -> Void) {
URLSession.shared.dataTask(with: dynamicLinkURL) { (data, response, error) in
    guard error == nil else {
        print("Found Error \(String(describing: error?.localizedDescription)))")
        return
    }
    guard let shortHandURL = response?.url, shortHandURL != dynamicLinkURL else {
        print("Thats Weird, my dynamic link has no URL")
        onCompletion(false)
        return
    }
    onCompletion(true)
}.resume()

}

Purnendu roy
  • 818
  • 8
  • 15
0

I was facing the same issue for SHORT URLs with pod 'Firebase/DynamicLinks', '~> 6.21.0'

  • It's better to urlEncode all components before creating a Dynamic Link.
  • You might be using the wrong custom schema for dynamic links. In the case of the Short URL, the schema is processed for some reason. Debug you shortened URL by appending ?d=1 and you will see a chart which depicts the flow of dynamic link in different cases.

enter image description here

After clicking on the Custom Schema you will be redirected to a URL which will look something like this

enter image description here

The struck away thing is my schema.

I have mentioned the schema retrieved above in the below statement

[FIROptions defaultOptions].deepLinkURLScheme = @"xxx.xxxxx.xxxxxx";

Call [FIRApp configure]; after setting deepLinkURLScheme.

DeltaCap019
  • 6,532
  • 3
  • 48
  • 70