ios facebook 登录问题 - canOpenURL:URL 失败:“fbauth2:///” - 错误:“(空)”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32663382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
facebook login issue - canOpenURL: failed for URL: "fbauth2:///" - error: "(null)"
提问by sfbayman
When I click on login with Facebook button, it is opening safari browser and getting closed immediately. Noticed error on the console.
当我点击使用 Facebook 按钮登录时,它正在打开 safari 浏览器并立即关闭。在控制台上注意到错误。
App delegate method:
应用委托方法:
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
print("###### URL : ")
print(url)
print("###### App : ")
print(app)
print(options["UIApplicationOpenURLOptionsSourceApplicationKey"])
return FBSDKApplicationDelegate.sharedInstance().application(app, openURL: url, sourceApplication: options["UIApplicationOpenURLOptionsSourceApplicationKey"] as! String,
annotation: nil)
}
2015-09-18 18:37:51.410 [21036:5050465] -canOpenURL: failed for URL: "fbauth2:///" - error: "(null)" 2015-09-18 18:37:51.417[21036:5050465] -canOpenURL: failed for URL: "fbauth2:///" - error: "(null)" ###### URL : fb4554284912963222://authorize/?error_code=100&error_message=Invalid+Scope%3A+public&state=%7B%22challenge%22%3A%222ZmK6R5F05d%252F060TkCqj8SjPLjc%253D%22%2C%220_auth_logger_id%22%3A%223C79F2C8-61B9-470E-AE1B-E1C68435DB83%22%2C%22com.facebook.sdk_client_state%22%3Atrue%2C%223_method%22%3A%22sfvc_auth%22%7D&e2e=%7B%22init%22%3A145973.000512302%7D#_=_ ###### App : Optional(com.apple.SafariViewService) nil ###### err: Optional(Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=100, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Invalid Scope: public, com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0})
IDE : xcode 7
Language : Swift2
Facebook SDK : 4.6.0
Parse: 1.8.4
IDE:xcode 7
语言:Swift2
Facebook SDK:4.6.0
解析:1.8.4
I have also verified .plist is having all keys which are required. Also verified the bundle identifier for typo mistakes. All look good. Facebook is active.
我还验证了 .plist 具有所有必需的密钥。还验证了包标识符的拼写错误。一切看起来都不错。脸书很活跃。
Any help?
有什么帮助吗?
回答by EdoBen
I have the same warning, but in Facebook Docs there is an answer.
我有同样的警告,但在 Facebook Docs 中有一个答案。
This is an Xcode warning indicating the the canOpenURL: call returned false. As long as you have configured the LSApplicationQueriesSchemes entry in your plist as described above, you can ignore this warning
这是一个 Xcode 警告,指示 canOpenURL: 调用返回 false。只要你按照上面的描述在你的 plist 中配置了 LSApplicationQueriesSchemes 条目,你就可以忽略这个警告
回答by Chris Pan
The "-canOpenURL: failed for URL" warning is a red herring and simply means the FB app is not installed on the device/simulator you're running on.
“-canOpenURL: failed for URL”警告是一个红鲱鱼,仅表示 FB 应用程序未安装在您正在运行的设备/模拟器上。
It looks like you're requesting an invalid scope (aka permission) of "Public". Can you include your code that includes what permissions you are asking? public_profile is probably what you want (and what the SDK defaults to if none are provided).
看起来您正在请求“公共”的无效范围(又名权限)。您可以包含包含您要求的权限的代码吗?public_profile 可能是你想要的(如果没有提供,SDK 默认使用什么)。
More importantly, do NOTadd fbauth2 to your CFBundleURLSchemes as that will break login flows. As Himanshu pointed out, those entries should be entered under LSApplicationQueriesSchemes in our plist.
更重要的是,不要将 fbauth2 添加到您的 CFBundleURLSchemes 中,因为这会破坏登录流程。正如 Himanshu 指出的那样,这些条目应该在我们的 plist 中的 LSApplicationQueriesSchemes 下输入。
回答by Himanshu Mahajan
If you're recompiling with iOS SDK 9.0, add the following to your application's plist if you're using a version of the Facebook SDK v4.6.0 or above:
如果您使用 iOS SDK 9.0 重新编译,如果您使用的是 Facebook SDK v4.6.0 或更高版本,请将以下内容添加到应用程序的 plist 中:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
To prepare the facebook integration supported to iOS 9, go through Facebook Integraion for iOS 9 guidelines
要准备支持 iOS 9 的 facebook 集成,请阅读Facebook Integraion for iOS 9 指南
To check version of facebook SDK, use below line of code:
要检查 facebook SDK 的版本,请使用以下代码行:
print("SDK version \(FBSDKSettings .sdkVersion())")
回答by ZAFAR007
This is an Xcode warning indicating the the canOpenURL: call returned false. As long as you have configured the
LSApplicationQueriesSchemes
entry in your plist as described above, you can ignore this warning.
这是一个 Xcode 警告,指示 canOpenURL: 调用返回 false。只要
LSApplicationQueriesSchemes
您按照上述方式在 plist 中配置了条目,就可以忽略此警告。
Go to this LinkSelect Your App, And configure your info.plist
转到此链接选择您的应用程序,并配置您的info.plist
import
And add this code in your AppDelegate
import
并将此代码添加到您的 AppDelegate
import FBSDKCoreKit .
import FBSDKLoginKit
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
}
回答by sfbayman
I have missed the importing FBSDKCoreKit
. Later it started working on the simulator but not on the iPhone device.
我错过了导入FBSDKCoreKit
。后来它开始在模拟器上工作,但不在 iPhone 设备上。
Also noticed the following FAQ on the Facebook site. Why do I see console messages like
还注意到 Facebook 网站上的以下常见问题解答。为什么我会看到类似的控制台消息
'canOpenURL: failed for URL: "fb...://'
'canOpenURL:URL 失败:“fb...://”
or ? This is a Xcode warning indicating the canOpenURL:
call returned false. As long as you have configured the LSApplicationQueriesSchemes
entry in your plist
as described above, you can ignore this warning
或者 ?这是一个 Xcode 警告,指示canOpenURL:
调用返回 false。只要LSApplicationQueriesSchemes
您plist
按照上面的描述在您的条目中配置了该条目,您就可以忽略此警告
Regarding not working on the iPhone device, please refer: Parse API - Facebook login not working on the iPhone device
关于不能在 iPhone 设备上工作,请参考: Parse API - Facebook login not working on the iPhone device
回答by Muzammil
You need to add this method if your app is running on iOS9 or above.
如果您的应用在 iOS9 或更高版本上运行,则需要添加此方法。
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
return [[FBSDKApplicationDelegate sharedInstance] application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
}
In case you need a Swift version:
如果您需要 Swift 版本:
@available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return SDKApplicationDelegate.shared.application(app,
open: url,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation] as Any)
}
回答by Rob Schlackman
I figured out my issue. It was just the syntax in loginButtonClicked function. The error message was leading me down the wrong path. Here is the working code.
我想通了我的问题。这只是 loginButtonClicked 函数中的语法。错误消息使我走上了错误的道路。这是工作代码。
@objc func loginButtonClicked() {
self.login = FBSDKLoginManager()
self.login.logIn(withReadPermissions: ["public_profile"], from: self, handler: {(result, error) -> Void in
if error != nil {
print("Process error")
}
else if (result?.isCancelled)! {
print("Cancelled")
}
else {
print("Logged in")
DispatchQueue.main.async(execute: {
let viewController:UIViewController = self.storyboard?.instantiateViewController(withIdentifier: "UITabBarController") as! UITabBarController
self.present(viewController, animated: true, completion: nil)
})
}
})
}
回答by Paul Slm
You have an extra "/" in your url "fbauth2:///".
您的网址“fbauth2:///”中有一个额外的“/”。
Then you can see "error_message=Invalid+Scope" in the url, you should probably check the permissions of your app: https://developers.facebook.com/docs/facebook-login/permissions/v2.4
然后您可以在 url 中看到“error_message=Invalid+Scope”,您可能应该检查您的应用程序的权限:https: //developers.facebook.com/docs/facebook-login/permissions/v2.4
回答by Phil
The issue is due to App Transport Security introduced in iOS 9.
该问题是由 iOS 9 中引入的 App Transport Security 引起的。
There are two solutions, both deal with fixing your info.plist file
有两种解决方案,都用于修复您的 info.plist 文件
Here's a guide http://discoverpioneer.com/blog/2015/09/18/updating-facebook-integration-for-ios-9/
这是一个指南http://discoverpioneer.com/blog/2015/09/18/updating-facebook-integration-for-ios-9/