我通过Cocoapods安装了Facebook的Swift:
pod 'FacebookCore', :git => "https://github.com/facebook/facebook-sdk-swift"
pod 'FacebookLogin', :git => "https://github.com/facebook/facebook-sdk-swift"
我遵循了Facebook的Swift (https://developers.facebook.com/docs/swift/login)的登录说明,但无法让它正常工作。
在我的视图控制器中,我有以下内容:
@objc fileprivate func facebookSignIn() {
let loginManager = LoginManager()
print("LOGIN MANAGER: \(loginManager)")
loginManager.logIn([ .publicProfile, .email ], viewController: self) { loginResult in
print("LOGIN RESULT! \(loginResult)")
switch loginResult {
case .failed(let error):
print("FACEBOOK LOGIN FAILED: \(error)")
case .cancelled:
print("User cancelled login.")
case .success(let grantedPermissions, let declinedPermissions, let accessToken):
print("Logged in!")
print("GRANTED PERMISSIONS: \(grantedPermissions)")
print("DECLINED PERMISSIONS: \(declinedPermissions)")
print("ACCESS TOKEN \(accessToken)")
}
}
}
“登录经理:等等”当我单击按钮并打开web视图时打印。我可以通过Facebook登录,然后网页视图变为空白,什么也不会发生。该应用程序显示在我的Facebook应用程序中,因此已经进行了一些授权,但如果我单击web视图中的“完成”按钮,回调的结果是.cancelled
和“用户取消登录”。是印出来的。
我在我的权利中添加了密钥链共享,并更新了我的info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string> [ FB STRING ] </string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>[ APP ID ]</string>
<key>FacebookDisplayName</key>
<string>[ APP NAME ]</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
我甚至更改了我的NSAppTransportSecurity
设置。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
我知道这是对iOS 9 Facebook登录模拟器-canOpenURL:-canOpenURL失败:“fbauth2://”-错误:"(null)“和如何在iOS 10上使用Facebook iOS SDK的复制,但似乎没有一个解决方案适合我,除非我错过了什么?如有任何建议,敬请见谅。
还打印了几个错误:
[App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
[error] error: (6922) I/O error for database at /var/mobile/Containers/Data/Application/F3D8E126-B0CC-4C06-81A5-D7A7F849B3BD/Documents/OfflineModel2.sqlite. SQLite error code:6922, 'disk I/O error'
当我没有在我的设备上安装FB应用程序时,我得到:
-canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
发布于 2016-10-06 18:31:42
您必须用以下方法替换原来的启动和openurl AppDelegate方法:
public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool
{
return SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
}
public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
{
return SDKApplicationDelegate.shared.application(app, open: url, options: options)
}
发布于 2016-11-30 10:52:23
Swift 3和Swift 4
将此添加到AppDelegate.swift中
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)
}
发布于 2016-12-30 07:43:20
不建议使用FBSDK库。在Facebook的Github存储库中可以找到较新的库。
对于此特定错误,请实现以下应用程序方法。
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return SDKApplicationDelegate.shared.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return SDKApplicationDelegate.shared.application(app, open: url, options: options)
}
https://stackoverflow.com/questions/39899327
复制相似问题