2

Facebook リンクを開こうとしていますが、次のコードを使用すると、iOS の URL プロトコルに準拠します。

NSString *url = [self.dataSource getFacebookURL];
url = [url stringByReplacingOccurrencesOfString:@"http://www.facebook.com/" withString:@"fb://profile/"];
NSLog(@"LINK: %@", url);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

しかし、プロファイルまたはページ (組織など) を読み込もうとすると、最後に開いたままの画面が常に表示されます。ページとプロフィールに直接リンクする方法はありますか? こちらで説明されている手順に従いましたが、成功しませんでした。

リンクしたいページは「https://www.facebook.com/junction11」です。

ありがとう、マックス

修理

そこで、グループ/個人/ページのグラフ値を最初にロードし、それらを解析してから、Facebook-ID を使用して新しい URL を作成するという解決策を見つけました。コードは機能し (よくわかりません)、次のようになります。

// Look at graph page instead of www page
NSString *dataURL = [url stringByReplacingOccurrencesOfString:@"www" withString:@"graph"];
// Load data and parse using JSON parser
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:dataURL]];
NSError *error;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

if (!error) { NSLog(@"ERROR: %@", error); return; }

// If no error occurred, make new url and replace the username by the facebook-ID
url = [url stringByReplacingOccurrencesOfString:[dictionary objectForKey:@"username"] withString:[dictionary objectForKey:@"id"]];
// And voilà, it works :]
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

ありがとうグーグルと時間...

4

1 に答える 1

1
NSURL *url = [NSURL URLWithString:@"fb://profile/<id>"];
[[UIApplication sharedApplication] openURL:url];

スキーム

fb://profile – Open Facebook app to the user’s profile

fb://friends – Open Facebook app to the friends list

fb://notifications – Open Facebook app to the notifications list (NOTE: there appears to be a bug with this URL. The Notifications page opens. However, it’s not possible to navigate to anywhere else in the Facebook app)

fb://feed – Open Facebook app to the News Feed

fb://events – Open Facebook app to the Events page

fb://requests – Open Facebook app to the Requests list

fb://notes – Open Facebook app to the Notes page

fb://albums – Open Facebook app to Photo Albums list
于 2012-12-29T19:39:43.420 に答える