无法启动本机 Facebook 应用程序
Not able to launch native Facebook app
我正在尝试启动一个 Facebook 页面,首先我检查它是否可以在本机应用程序中打开,然后在 Safari 中打开,如果不能。我确实安装了 Facebook,但它总是在 Safari 中打开页面。这是我使用的代码。
let fbId = "ID" // this is of course a dummy value now
let url = "fb://profile/\(fbId)"
let fbURL = NSURL(string: url)
if UIApplication.sharedApplication().canOpenURL(fbURL!){
UIApplication.sharedApplication().openURL(fbURL!)
}
else {
//redirect to safari because the user doesn't have Facebook
UIApplication.sharedApplication().openURL(NSURL(string:"http://facebook.com/\(fbId)")!)
}
知道为什么这不起作用吗?
如果您正在构建 iOS 9.0,则需要更新您的 Info.plist。
IMPORTANT If your app is linked on or after iOS 9.0, you must declare
the URL schemes you want to pass to this method. Do this by using the
LSApplicationQueriesSchemes array in your Xcode project’s Info.plist
file. For each URL scheme you want your app to use with this method,
add it as a string in this array.
If your (iOS 9.0 or later) app calls this method using a scheme you
have not declared, the method returns NO, whether or not an
appropriate app for the scheme is installed on the device.
对于 iOS 9,您必须使用 Info.plist 中的 LSApplicationQueriesSchemes
键将您的应用调出的 url 列入白名单。
所以将此代码添加到您的 plist 文件中:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fb</string>
<string>fbapi</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>fb-messenger-api</string>
<string>twitter</string>
<string>whatsapp</string>
<string>wechat</string>
<string>line</string>
<string>instagram</string>
<string>kakaotalk</string>
<string>mqq</string>
<string>vk</string>
<string>comgooglemaps</string>
</array>
您也可以删除不想使用的方案。
希望对您有所帮助!
我正在尝试启动一个 Facebook 页面,首先我检查它是否可以在本机应用程序中打开,然后在 Safari 中打开,如果不能。我确实安装了 Facebook,但它总是在 Safari 中打开页面。这是我使用的代码。
let fbId = "ID" // this is of course a dummy value now
let url = "fb://profile/\(fbId)"
let fbURL = NSURL(string: url)
if UIApplication.sharedApplication().canOpenURL(fbURL!){
UIApplication.sharedApplication().openURL(fbURL!)
}
else {
//redirect to safari because the user doesn't have Facebook
UIApplication.sharedApplication().openURL(NSURL(string:"http://facebook.com/\(fbId)")!)
}
知道为什么这不起作用吗?
如果您正在构建 iOS 9.0,则需要更新您的 Info.plist。
IMPORTANT If your app is linked on or after iOS 9.0, you must declare the URL schemes you want to pass to this method. Do this by using the LSApplicationQueriesSchemes array in your Xcode project’s Info.plist file. For each URL scheme you want your app to use with this method, add it as a string in this array.
If your (iOS 9.0 or later) app calls this method using a scheme you have not declared, the method returns NO, whether or not an appropriate app for the scheme is installed on the device.
对于 iOS 9,您必须使用 Info.plist 中的 LSApplicationQueriesSchemes
键将您的应用调出的 url 列入白名单。
所以将此代码添加到您的 plist 文件中:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fb</string>
<string>fbapi</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>fb-messenger-api</string>
<string>twitter</string>
<string>whatsapp</string>
<string>wechat</string>
<string>line</string>
<string>instagram</string>
<string>kakaotalk</string>
<string>mqq</string>
<string>vk</string>
<string>comgooglemaps</string>
</array>
您也可以删除不想使用的方案。
希望对您有所帮助!