如何检测iOS上是否安装了Facebook应用程序?

Tom*_*aid 20 facebook url-scheme ios

在iOS上,您可以通过打开以下URL来启动Facebook应用程序并链接到个人资料:fb:// profile/12345

唯一的问题是,如果没有安装Facebook应用程序,没有任何反应.

有没有办法检测是否安装了应用程序或是否支持url方案fb://?

这也将广泛应用于Twitter等其他应用程序.

Nik*_* M. 48

BOOL isInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]

if (isInstalled) {

} else {

}
Run Code Online (Sandbox Code Playgroud)

  • 您还需要将LSApplicationQueriesSchemes键包含在iOS 9的info.plist中,其值为"fb". (9认同)

Tom*_*voy 6

尝试使用该canOpenURL:功能

NSURL *fbURL = [NSURL URLWithString:@"fb://"];//or whatever url you're checking

if ([[UIApplication sharedApplication] canOpenURL:fbURL])
{
  //open it etc  
}
Run Code Online (Sandbox Code Playgroud)