谢谢。
谢谢。
以下是Facebook应用程序使用的一些方案,源链接中还有更多内容:
NSURL *url = [NSURL URLWithString:@"fb://profile/<id>"];
[[UIApplication sharedApplication] openURL:url];
fb://profile – 打开用户资料的Facebook应用程序
fb://friends – 打开Facebook应用程序的好友列表
fb://notifications – 打开Facebook应用程序的通知列表(注意:此URL存在问题。通知页面会打开,但无法在Facebook应用程序中导航到其他任何地方)
fb://feed – 打开Facebook应用程序的新闻源
fb://events – 打开Facebook应用程序的活动页面
fb://requests – 打开Facebook应用程序的请求列表
fb://notes – 打开Facebook应用程序的笔记页面
fb://albums – 打开Facebook应用程序的照片相册列表
如果在打开此URL之前要检查用户是否拥有Facebook应用程序,可以执行以下操作(如下面的另一个答案中所述):
if ([[UIApplication sharedApplication] canOpenURL:nsurl]){
[[UIApplication sharedApplication] openURL:nsurl];
}
else {
//Open the url as usual
}
Info.plist
中添加白名单以使其工作。请参见http://useyourloaf.com/blog/querying-url-schemes-with-canopenurl.html。 - haxpor10153231379946729
。有什么想法吗? - hientrq只需使用https://graph.facebook.com/(your_username或页面名称)来获取您的页面ID,然后您就可以查看所有详细信息和您的ID。
在您的IOS应用程序中使用:
NSURL *url = [NSURL URLWithString:@"fb://profile/[your ID]"];
[[UIApplication sharedApplication] openURL:url];
fb://page/…
URL不再有效。 显然它已被 fb://profile/…
替换,尽管页面不是个人资料。我在MonoTouch中使用了以下方法,我相信纯Obj-C的方法并不会有太大差异。我将其用于一个具有不断变化的URL的类中,这就是为什么我没有将它放在if/elseif语句中的原因。
NSString *myUrls = @"fb://profile/100000369031300|http://www.facebook.com/ytn3rd";
NSArray *urls = [myUrls componentsSeparatedByString:@"|"];
for (NSString *url in urls){
NSURL *nsurl = [NSURL URLWithString:url];
if ([[UIApplication sharedApplication] canOpenURL:nsurl]){
[[UIApplication sharedApplication] openURL:nsurl];
break;
}
}
在您的应用程序转换到Safari/Facebook之前,并不总是会调用break语句。我假设当您回到应用程序时,您的程序将在那里停止并调用该语句。
+(void) openUrlInBrowser:(NSString *) url
{
if (url.length > 0) {
NSURL *linkUrl = [NSURL URLWithString:url];
[[UIApplication sharedApplication] openURL:linkUrl];
}
}
+(void) openUrl:(NSString *) urlString
{
//check if facebook app exists
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
// Facebook app installed
NSArray *tokens = [urlString componentsSeparatedByString:@"/"];
NSString *profileName = [tokens lastObject];
//call graph api
NSURL *apiUrl = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@",profileName]];
NSData *apiResponse = [NSData dataWithContentsOfURL:apiUrl];
NSError *error = nil;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:apiResponse options:NSJSONReadingMutableContainers error:&error];
//check for parse error
if (error == nil) {
NSString *profileId = [jsonDict objectForKey:@"id"];
if (profileId.length > 0) {//make sure id key is actually available
NSURL *fbUrl = [NSURL URLWithString:[NSString stringWithFormat:@"fb://profile/%@",profileId]];
[[UIApplication sharedApplication] openURL:fbUrl];
}
else{
[UrlUtils openUrlInBrowser:urlString];
}
}
else{//parse error occured
[UrlUtils openUrlInBrowser:urlString];
}
}
else{//facebook app not installed
[UrlUtils openUrlInBrowser:urlString];
}
}
"message": "(#803) 无法通过用户名(user.name)查询用户"
- Jasperswift 3
if let url = URL(string: "fb://profile/<id>") {
if #available(iOS 10, *) {
UIApplication.shared.open(url, options: [:],completionHandler: { (success) in
print("Open fb://profile/<id>: \(success)")
})
} else {
let success = UIApplication.shared.openURL(url)
print("Open fb://profile/<id>: \(success)")
}
}
今天刚验证过,如果你想要打开Facebook的页面,可以使用"fb://page/{Page ID}"
页面ID可以在页面底部的关于部分找到。
对于我的用例,在Xamarin.Forms中,您可以使用此代码片段在应用程序中打开,否则在浏览器中打开。
Device.OpenUri(new Uri("fb://page/{id}"));
之前的方法fb://profile/[ID]
已经失效。
请尝试使用fb://profile?id=[ID]
使用示例:
// Open Profile or page
// To open in Application
if UIApplication.shared.canOpenURL(URL(string: "fb://profile?id=vikramchaudhary.ios")!) {
UIApplication.shared.open(URL(string: "fb://profile?id=vikramchaudhary.ios")!, options: [:], completionHandler: nil)
} else {
// To open in safari
UIApplication.shared.open(URL(string: "https://facebook.com/vikramchaudhary.ios/")!, options: [:], completionHandler: nil)
}
NSURL *fbNativeAppURL = [NSURL URLWithString:@"fb://page/yourPageIDHere"] [[UIApplication sharedApplication] openURL:fbNativeAppURL]
这将在Safari中打开URL:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/comments.php?href=http://wombeta.jiffysoftware.com/ViewWOMPrint.aspx?WPID=317"]];
对于 iPhone,如果已安装 Facebook 应用程序,则可以使用以 fb:// 开头的 URL 启动 Facebook 应用程序
更多信息可以在此处找到:http://iphonedevtools.com/?p=302 还可以在此处找到:http://wiki.akosma.com/IPhone_URL_Schemes#Facebook
从上述网站盗取:
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
要启动以上的URL:
NSURL *theURL = [NSURL URLWithString:@"fb://<insert function here>"];
[[UIApplication sharedApplication] openURL:theURL];