iOS 允许应用程序通过自定义 URL 方案的框架打开其他应用程序。与 Facebook 集成允许用户通过这些 URL 从 Facebook 应用程序直接导航到您的应用程序,我们将其称为“深度链接”。例如,当您的应用代表其用户向 Facebook 发帖时,它可以在帖子中包含这些 URL 或深层链接之一。然后,当用户的朋友与帖子互动并将他们定向到您的应用程序时,您将收到此链接,您可以对其进行处理以决定将他们放在哪个视图上。
我可以从 iPhone 模拟器的测试应用程序中共享“正常”链接。现在我想分享来自 iPhone 模拟器的深层链接。但是,一旦我更改代码以使用深层链接,共享过程就会失败。
分享使用这组参数(注:链接为普通网址):
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];
共享不适用于这组参数(现在链接是深层链接):
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];
这是我用来实际共享链接的代码:
[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);
}
}
}
}];
这是我尝试与第二组参数共享时看到的错误:
我只是在提供我的登录凭据后得到它。那不是很丰富。我不知道在哪里看。甚至可以分享来自 iPhone 模拟器的深层链接吗?
编辑:深度链接和自定义方案是记录在案的 Facebook 应用程序功能。URL Scheme Suffix
Facebook 应用程序设置页面中有一个可选字段。