Swi*_*y89 26 facebook ios facebook-ios-sdk swift
我正在使用Xcode 7.0,在iOS 9.0.2上测试并使用Facebook SDK 4.7.0.
当我登录用户时,大部分时间一切正常,但有时我会不断收到此错误,我不明白为什么!
该操作无法完成.(com.facebook.sdk.login错误308.)
经过研究,我发现有些人在使用parse.com FBUtils和官方FBSDK同时登录时遇到错误,但我只FBSDK在我的项目中使用.
所以我的问题是,为什么我会收到此错误,如何摆脱它?
编辑 - 添加代码
这是我的登录逻辑:
func loginWithFacebook(sender: UIViewController, completion: (profile: FBSDKProfile?, token: String?, cancelled: Bool, error: String?) -> Void ) {
FBSDKProfile.enableUpdatesOnAccessTokenChange(true)
NSNotificationCenter.defaultCenter().addObserver( sender , selector: "onProfileUpdated:", name:FBSDKProfileDidChangeNotification, object: nil)
let loginManager = FBSDKLoginManager()
loginManager.logInWithReadPermissions(["email", "public_profile"], fromViewController: sender) { (result: FBSDKLoginManagerLoginResult!, error: NSError!) -> Void in
if error != nil {
print("ERROR")
completion(profile: nil, token: nil, cancelled: false, error: error.localizedDescription)
print(error.localizedDescription)
} else if result.isCancelled {
print("CANCELLED")
completion(profile: nil, token: nil, cancelled: true, error: nil)
} else {
print("NO ERROR")
if FBSDKProfile.currentProfile() == nil {
print("PROFILE IS NIL")
completion(profile: nil, token: result.token.tokenString, cancelled: false, error: nil)
} else {
print("PROFILE IS NOT NIL")
completion(profile: FBSDKProfile.currentProfile(), token: result.token.tokenString, cancelled: false, error: nil)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Zai*_*han 101
对于Xcode8 - iOS10,
在目标修复我的问题的功能选项卡中启用钥匙串共享.
更多细节可以在这里找到:https://github.com/facebook/facebook-sdk-swift/issues/51
对于Xamarin Studio(由@Kenneth推荐),
将Entitlements.plist文件添加到iOS项目中的选项下的自定义权利iOS Bundle Signing.
Swi*_*y89 13
我找到了解决这个问题的方法.我正在创建一个登录管理器的实例,我需要它:
let loginManager = FBSDKLoginManager()
Run Code Online (Sandbox Code Playgroud)
然后我用它来登录,我在我的注销方法中创建了另一个实例.我通过创建一个在整个应用程序中使用的惰性变量修复了这个问题:
lazy var fbLoginManager: FBSDKLoginManager = {
return FBSDKLoginManager()
}()
Run Code Online (Sandbox Code Playgroud)
UPDATE
Facebook已经意识到了这个漏洞并且正在调查它.我发现我的解决方案并不总是有效并且已将我的代码更新为以下内容并且从未见过它:
private var _fbLoginManager: FBSDKLoginManager?
var fbLoginManager: FBSDKLoginManager {
get {
if _fbLoginManager == nil {
_fbLoginManager = FBSDKLoginManager()
}
return _fbLoginManager!
}
}
Run Code Online (Sandbox Code Playgroud)
当退出Facebook时,您需要调用_fbLoginManager = nil并在下次用于登录时重新创建实例.当使用相同的实例在注销后重新登录时,问题似乎更频繁地发生但是当存在多个实例时,问题发生的更多,FBSDKLoginManager因此如上所述声明它似乎已经解决了问题.
2018年10月.
原因:"+"符号在challengeReceived字符串中被替换为"".FBSDK中的问题.
快速而肮脏的修复:https: //github.com/facebook/facebook-objc-sdk/pull/922
具体来说,替换FBSDKLoginManager中的第233行:
NSString *challengeExpected = [self loadExpectedChallenge];
Run Code Online (Sandbox Code Playgroud)
同
NSString *challengeExpected = [[self loadExpectedChallenge] stringByReplacingOccurrencesOfString:@"+" withString:@" "];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15184 次 |
| 最近记录: |