gpt4 book ai didi

ios - 在 swift 3.0 中实现 Facebook 和 Google 登录 API

转载 作者:行者123 更新时间:2023-11-30 12:57:28 25 4
gpt4 key购买 nike

我挣扎了一夜半天才放弃,来这里寻求帮助。我已经在 stackoverflow 上阅读了几个线程,但任何解决方案似乎都有效,但即使应用程序在启动时崩溃

2016-10-26 16:03:58.793 MotivaMe[3997:404331] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MotivaMe.ViewController 0x7ff1a0407700> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key loginButtonFB.'

已修复 请参阅底部的解决方案

编辑:编译器现在显示:“应用程序的实现:openURL:sourceApplication:注释:未找到。请将处理程序添加到您的应用程序委托(delegate)中。”特别是在身份验证之后,我陷入困境并且没有重定向到应用程序

这是我第一次尝试为 iOS 编写代码,所以我对目前仍在学习的 CocoaTouch 还没有那么有信心。感谢您的任何帮助(对修复的解释将非常感激,因为我不知道出了什么问题,谢谢大家)

这是 AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{

FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")

GIDSignIn.sharedInstance().delegate = self

return true

}

func application(application: UIApplication, openURL url: NSURL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
{

let googleDidHandle = GIDSignIn.sharedInstance().handle(
url as URL!,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation])

let facebookDidHandle = FBSDKApplicationDelegate.sharedInstance().application(
application,
open: url as URL!,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String,
annotation: options [UIApplicationOpenURLOptionsKey.annotation])

return googleDidHandle || facebookDidHandle
}

// The sign-in flow has finished and was successful if |error| is |nil|.
func sign(_ doLoginGoogle: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!)
{
if (error == nil)
{
// Perform any operations on signed in user here.
let userId = user.userID // For client-side use only!
let idToken = user.authentication.idToken // Safe to send to the server
let fullName = user.profile.name
let givenName = user.profile.givenName
let familyName = user.profile.familyName
let email = user.profile.email
// ...
print(userId,idToken,fullName,givenName,familyName,email)
}
else
{
print("\(error.localizedDescription)")
}
}

这是 ViewController.swift

override func viewDidLoad() {
super.viewDidLoad()


GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().signInSilently()
}

@IBOutlet weak var doLoginFacebook: FBSDKLoginButton!
@IBOutlet weak var doLoginGoogle: GIDSignInButton!

func loginButtonDidLogOut(_ doLoginFacebook: FBSDKLoginButton!)
{
print("Did log out of facebook")
}

func loginButton(_ doLoginFacebook: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!)
{
if error != nil
{
print(error)
return
}
else
{
if(FBSDKAccessToken.current() != nil) //useless check but want to get confident with the api
{
//TODO implement switching pages on login
print("Sucessfully logged into facebook!")
}
}
}

最佳答案

我强烈怀疑您的 socket 连接之一卡在了您的 Stroyboard 或 Nib 中。这种情况可能会时不时地发生,因此您需要确保如果更新/删除 socket 连接,也会从接口(interface)构建器中删除。

要解决此问题,请转到界面编辑器,然后选择 View Controller 。然后转到右侧面板上的此处。

enter image description here

在那里您应该仍然可以看到已连接的loginButtonFB,旁边有一个小解释标记。删除此连接,应该可以解决您的问题。

关于ios - 在 swift 3.0 中实现 Facebook 和 Google 登录 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40264839/

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