1

I am trying to open facebook app via AppLinks url , it opens user profile/page but does not show button "back to referer app" , I am providing "referer_app_link" data , I have generated JSON by this reference http://applinks.org/documentation/#applinknavigationprotocol

    NSDictionary *dict = @{
                       @"target_url" : @"fb://profile/USER_ID",
                       @"referer_app_link" : @{
                               @"target_url" : @"MY WEBSITE",
                               @"url" : @"CALLBACK URL",
                               @"app_name" : @"MY APP NAME",
                               @"app_store_id" : @"MY APP STORE ID"
                               }
                       };

NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:0 error:nil];
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

jsonString = [jsonString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSString *stringUrl = [NSString stringWithFormat:@"fb://applinks?al_applink_data=%@",jsonString];
NSLog(@"String url is %@",stringUrl);
NSURL *url = [NSURL URLWithString:stringUrl];

if([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url];
} else {
    NSLog(@"Cant open %@",url);
}

any ideas ? is Facebook supposed to have "back button" at all ? my url scheme is set up correctly ...

Update: NSDictionary contains all valid values , I dont want to publish them at the moment , but url , name , store id ... etc all are valid

Update #2: Since iOS 9 , this is done by iOS System automatically.

ogres
  • 3,660
  • 1
  • 17
  • 16
  • If I am not mistaken the url will just use FB as a passthrough to the actual fb registered app in IOS or the web. In which case a 3rd party app can call your fb app and pass it some parameters. – Paulo Jan 06 '15 at 14:00
  • I suppose the dictionary contents point to an actual live fb app because certainly @'MyY APP STORE ID"is definitely invalid and should contain digits, the URL should also be a valid app url scheme installed in the device. – Paulo Jan 06 '15 at 14:06
  • @Paulo I want to open Facebook and navigate to someones User profile , not any 3rd party app , opening works , but without back button, also , dictionary contains valid values , I just changed them with placeholders to display here , – ogres Jan 06 '15 at 14:08
  • Let me get it straight - you just want to view a friends profile then go back to your app? Am I correct - You do not really want to navigate to a third party FB app/ – Paulo Jan 06 '15 at 14:15
  • . I do understand that applink itself is a 3rd party FB app not really coded by FB. I'll post an answer if I get more understanding. If it will help - I am able to select (from all my friends and display my friends profile within my app using the native FB sdks in IOS 6.0 (have not upgraded the app for sometime because of an incompatible 3rd party SDK), and I believe it should still be available – Paulo Jan 06 '15 at 14:31
  • I don't think Applink is supposed to be used for the purposes you specified - see this link: https://developers.facebook.com/docs/applinks/overview - In FB it is simply an app link that is imbedded within an FB story. You should look at the FB IOS SDK they do have some examples on opening a friends profile or accessing. – Paulo Jan 06 '15 at 14:38
  • look here http://applinks.org/documentation/#applinknavigationprotocol , facebook , it says to include referer app url for navigating back ... – ogres Jan 06 '15 at 14:48
  • YES but Facebook is not wired to comeback to your app from a profile page that is why you do not have that back button you are looking for. – Paulo Jan 06 '15 at 15:15
  • Thats my question :) if there is some way to achieve that – ogres Jan 06 '15 at 15:56
  • You need to use the FB IOS SDK - there is a sample app called HelloFacebook.app - You may have read this - the current code creates a list of friends with pics just add to the code to get the other fields. – Paulo Jan 06 '15 at 16:10
  • I dont want friends list or any other behavior , I only need to open profile with back button , fb suggests to use AppLinks rather than direct deep links ... – ogres Jan 06 '15 at 16:20
  • If you link to an FB Story or post - you can use app link to provide a link back to your app, what you want will not happen unless FB rewrites the FB Profile page Anyway I provided the code for you to do it within your app. – Paulo Jan 06 '15 at 16:28
  • There maybe another way - create a website / FB App that will do as you wish wired with app link - but given the complication it will be easier to just use the code I gave you to display the user profile in your app directly. – Paulo Jan 06 '15 at 16:32
  • There's no support for this functionality in the Facebook apps currently. You can PM me your use case and app ID, and we can consider this use case in the future. – Ming Li Jan 06 '15 at 19:00
  • @MingLi how can I send you a personal message ? stackoverflow does not have this functionality and you do not have any additional contact info in your profile ... – ogres Jan 07 '15 at 09:09

1 Answers1

0

applink is not wired into the FB friend profile page if you simply use the FB Custom URL to link into FB.APP or to safari it will not go back to your app automatically.

The alternative to this is to use the FB IOS SDK and Pick and display the remote user within your app as follows: (code from HelloFacebook sample app (comes with the SDK)

- (IBAction)pickFriendsClick:(UIButton *)sender {
   FBFriendPickerViewController *friendPickerController = [[FBFriendPickerViewController alloc] init];
     friendPickerController.title = @"Pick Friends";
     [friendPickerController loadData];

   // Use the modal wrapper method to display the picker.
   [friendPickerController presentModallyFromViewController:self animated:YES handler:
    ^(FBViewController *innerSender, BOOL donePressed) {
        if (!donePressed) {
            return;
       }

        NSString *message;

       if (friendPickerController.selection.count == 0) {
            message = @"<No Friends Selected>";
        } else {

            NSMutableString *text = [[NSMutableString alloc] init];

           // we pick up the users from the selection, and create a string that we use to update the text view
            // at the bottom of the display; note that self.selection is a property inherited from our base class
            for (id<FBGraphUser> user in friendPickerController.selection) {
                if ([text length]) {
                   [text appendString:@", "];
                }
               [text appendString:user.name];
           }
           message = text;
       }

        [[[UIAlertView alloc] initWithTitle:@"You Picked:"
                                 message:message
                                delegate:nil
                         cancelButtonTitle:@"OK"
                         otherButtonTitles:nil]
        show];
    }]; 

}

Note - the sample currently just picked the name property from the FBGraphUser Class instance ....

user will have other properties birthday, sex etc, just lookup header file within the SDK or look up FB documentation.

Paulo
  • 1,245
  • 10
  • 8
  • I do not want to pick friend or create custom view , sorry , the question is to open FB with params and back-return button ( profile,page,post ... does not matter ) , like Facebook app opens Facebook Messenger with back button which opens Facebook app again – ogres Jan 06 '15 at 16:25
  • Messenger and Facebook can go back and forth between each other because Facebook (the company) can write them to do so. If you need to display some information from Facebook inside the context of your app, you need to be using the FB SDK. – Brad Brighton Jan 06 '15 at 16:59
  • FB SDK does not have such behavior , sorry , this is not an answer for my question. I know what FB SDK does and what is FBFriend picker ... this has nothing to do with my question. – ogres Jan 07 '15 at 10:26
  • Ogres - what you want will not happen unless FB changes its code and I doubt if they will do it for you. The code I gave you can be modified to displays the user profile in detail and its part of the sample app shipped together with the FB SDK. – Paulo Jan 07 '15 at 11:12