gpt4 book ai didi

ios - Facebook 登录 iOS 10 一直有效,直到第二次按下按钮

转载 作者:行者123 更新时间:2023-11-28 16:09:54 24 4
gpt4 key购买 nike

我一直在使用 Swift 3 在 iOS 10 上为 Facebook 登录创建自定义按钮。不幸的是,在我第二次按下 UIButton 之前,Facebook 登录不会显示 SafariViewController。多亏了断点,我知道它调用了 loginManager.logIn() 但直到我第二次按下 UIButton 时它才进入回调。尽管如果我将 FacebookLoginButton() 与我的自定义一起使用,一切正常。我真的不知道出了什么问题。希望你能帮我。谢谢!

这是我的 View Controller :

import UIKit
import FacebookCore
import FacebookLogin

class ViewController: UIViewController {

override func viewDidLoad() {

self.view.backgroundColor = .blue

// Add a custom login button to your app
let myLoginButton = UIButton(type: .system)
myLoginButton.backgroundColor = .red
myLoginButton.frame = CGRect(x: 0, y: 0, width: 180, height: 40)
myLoginButton.center = view.center;
myLoginButton.setTitle("My Button", for: .normal)

// Handle clicks on the button
myLoginButton.addTarget(self, action: #selector(self.loginButtonClicked), for: .touchUpInside)

// Add the button to the view
view.addSubview(myLoginButton)
}

// Once the button is clicked, show the login dialog
func loginButtonClicked() {
let loginManager = LoginManager()
loginManager.logIn([.publicProfile], viewController: self) { (loginResult) in
switch loginResult {
case .failed(let error):
print(error)
case .cancelled:
print("User cancelled login.")
case .success(let grantedPermissions, let declinedPermissions, let accessToken):
print("Logged in!")
}
}
}

还有我的 info.plist(唯一的变化是我的应用名称和 ID 的占位符:

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb[A Number]</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>[My Facebook App ID]</string>
<key>FacebookDisplayName</key>
<string>[My App Name]</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>

更新:这已被 facebook 确认为错误 https://developers.facebook.com/bugs/622990254549819/is

最佳答案

问题与驻留在 Facebook SDK 中的方法有关

- (void)logInWithBehavior:(FBSDKLoginBehavior)loginBehavior  
{
__weak __typeof__(self) weakSelf = self;
[FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:^(FBSDKServerConfiguration *serverConfiguration, NSError *loadError) {
[weakSelf logInWithBehavior:loginBehavior serverConfiguration:serverConfiguration serverConfigurationLoadError:loadError];
}];
}

您将无法在 View 中登录,因为使用包含 LoginManager init 的按钮回调,FBSDKServerConfigurationManager 在您第一次按下登录按钮时为 null,但在第二次时为 init。

我已经解决了一个非常相似的问题,只需将管理器声明为全局变量并在 viewDidLoad 中初始化 LoginManager。

关于ios - Facebook 登录 iOS 10 一直有效,直到第二次按下按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39716675/

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