我正在尝试打开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]];
但是当试图加载个人资料或页面(即组织)时,它总是将我带到最后打开的屏幕。有没有直接链接到页面和配置文件的方法?我按照here所述的说明进行操作,但没有成功。
我要链接的页面是“https://www.facebook.com/junction11”,如果这有帮助......
谢谢,Max
FIX
所以我找到了一个解决方案,首先加载组/人/页面的图形值,解析它们,然后使用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]];
谢谢google和时间......
答案 0 :(得分: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