4

Deep Links

iOS allows apps to open other apps through a framework of custom URL schemes. Integrating with Facebook allows users to the navigate directly to your app from the Facebook app via these URLs, which we will refer to as "deep linking". For example, when your app posts to Facebook on behalf of its users, it can include one of these URLs, or deep links, in the post. Then, when the user's friends engage with the post and they are directed to your app, you will receive this link and you can process it to decide what view to land them on.

I can share "normal" links from my test app from the iPhone Simulator. Now I want to share deep links from the iPhone Simulator. But as soon as I change the code to use a deep link the sharing process fails.

The sharing works with this set of parameters (Note: The link is an ordinary URL):

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"Sharing Tutorial", @"name",
                               @"Build great social apps and get more installs.", @"caption",
                               @"Allow your users to share stories on Facebook from your app using the iOS SDK.", @"description",
                               @"https://developers.facebook.com/docs/ios/share/", @"link",
                               @"http://i.imgur.com/g3Qc1HN.png", @"picture",
                               nil];

The sharing does not work with this set of parameters (Now the link is a deep link):

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"Sharing Tutorial", @"name",
                               @"Build great social apps and get more installs.", @"caption",
                               @"Allow your users to share stories on Facebook from your app using the iOS SDK.", @"description",
                               @"fbAPPID://authorize#target_url=[MYURL]", @"link",
                               @"http://i.imgur.com/g3Qc1HN.png", @"picture",
                               nil];

This is the code I use to actually share the link:

[FBWebDialogs presentFeedDialogModallyWithSession:nil
                                       parameters:params
                                          handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                              if (error) {
                                                  // An error occurred, we need to handle the error
                                                  // See: https://developers.facebook.com/docs/ios/errors
                                                  NSLog([NSString stringWithFormat:@"Error publishing story: %@", error.description]);
                                              } else {
                                                  if (result == FBWebDialogResultDialogNotCompleted) {
                                                      // User cancelled.
                                                      NSLog(@"User cancelled.");
                                                  } else {
                                                      // Handle the publish feed callback
                                                      NSDictionary *urlParams = [self parseURLParams:[resultURL query]];

                                                      if (![urlParams valueForKey:@"post_id"]) {
                                                          // User cancelled.
                                                          NSLog(@"User cancelled.");

                                                      } else {
                                                          // User clicked the Share button
                                                          NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
                                                          NSLog(@"result %@", result);
                                                      }
                                                  }
                                              }
                                          }];

This is the error I see when I try to share with the second set of parameters:

Error display

I get it just after providing my login credentials. That not very informative. I don't know where to look. Is it even possible to share deep links from the iPhone Simulator?

EDIT: Deep Links and Custom Schemes are documented Facebook App features. There is an optional field for an URL Scheme Suffix in the Facebook Apps Settings page.

Jan Deinhard
  • 19,645
  • 24
  • 81
  • 137
  • I'm pretty sure only http/https are accepted. – Ming Li Jan 22 '14 at 18:24
  • Well, Deep Links are documented so I guess custom schemes should be accepted: https://developers.facebook.com/docs/ios/app-links – Jan Deinhard Jan 23 '14 at 08:24
  • I'm not sure I agree. That document shows you how to setup your app in a way such that it will accept deep links from Facebook. If you have deep linking turned on in your app settings, then sharing an http or https link will deep link into your app (using the fb{app_id} scheme), and the original url will be passed via the target_url parameter. – Ming Li Jan 23 '14 at 23:31
  • Could one of you tell me what link am I supposed to share after setup deep linking? is it "myappurl://" or "fbAPPID://authorize#target_url=[MYURL]" ? – Rodrigo Ruiz May 19 '14 at 04:27

0 Answers0