1

我正在尝试通过 AppLinks url 打开 facebook 应用程序,它会打开用户个人资料/页面,但不显示“返回引用应用程序”按钮,我正在提供“referer_app_link”数据,我已通过此参考http://applinks 生成 JSON。 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);
}

有任何想法吗 ?Facebook应该有“后退按钮”吗?我的 url 方案设置正确...

更新: NSDictionary 包含所有有效值,我现在不想发布它们,但是 url 、 name 、 store id ...等都是有效的

更新 #2: 从 iOS 9 开始,这是由 iOS 系统自动完成的。

4

1 回答 1

0

如果您只是使用 FB 自定义 URL 链接到 FB.APP 或 safari,applink 不会连接到 FB 朋友个人资料页面,它不会自动返回到您的应用程序。

替代方法是使用 FB IOS SDK 并在您的应用程序中选择并显示远程用户,如下所示:(来自 HelloFacebook 示例应用程序的代码(随 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];
    }]; 

}

注意 - 该示例当前刚刚从 FBGraphUser 类实例中选择了 name 属性...。

用户将拥有其他属性生日、性别等,只需在 SDK 中查找头文件或查找 FB 文档。

于 2015-01-06T16:24:17.270 回答