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]];
ありがとうグーグルと時間...