gpt4 book ai didi

ios - Facebook SDK 使用 Swift 3 iOS 10 登录

转载 作者:IT王子 更新时间:2023-10-29 05:32:21 25 4
gpt4 key购买 nike

我通过 Cocoapods 安装了 Facebook 的 Swift SDK:

pod 'FacebookCore', :git => "https://github.com/facebook/facebook-sdk-swift"
pod 'FacebookLogin', :git => "https://github.com/facebook/facebook-sdk-swift"

我已按照 Facebook 的 Swift SDK (https://developers.facebook.com/docs/swift/login) 中的登录说明进行操作,但无法正常工作。

在我的 View Controller 中,我有以下内容:

@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 View 时打印。我可以通过 Facebook 登录,然后 Web View 变为空白,什么也没有发生。该应用程序显示在我的 Facebook 应用程序中,因此已经进行了一些授权,但是如果我在 Web View 中单击“完成”按钮,回调的结果是 .cancelled 和“用户取消登录。 “打印出来。

我已将钥匙串(keychain)共享添加到我的权利中,并且更新了我的 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 login simulator -canOpenURL: failed for URL: "fbauth2:///" - error: "(null)" 的副本和 How to use Facebook iOS SDK on iOS 10但是那里的解决方案似乎都不适合我,除非我错过了什么?任何建议表示赞赏。

还打印了几个错误:

[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.)"

最佳答案

Swift 3Swift 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)
}

关于ios - Facebook SDK 使用 Swift 3 iOS 10 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39899327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com