简体   繁体   English

AppDelegate不符合Swift 3中的协议'GIDSignInDelegate'

[英]AppDelegate does not conform to protocol 'GIDSignInDelegate' in Swift 3

I'm trying to authenticate with Firebase using their Google Accounts by integrating Google Sign-In into app. 我正在尝试通过将Google登录集成到应用中来使用他们的Google帐户对Firebase进行身份验证。

Using: 使用:

  • Swift 3 斯威夫特3
  • Xcode 8 Xcode 8
  • Firebase 3.11.1 Firebase 3.11.1

I have implemented the two methods of GIDSignInDelegate in AppDelegate 我在AppDelegate中实现了GIDSignInDelegate的两种方法

// Sign-in flow has finished and was succcesful if error is nil:
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!){
if let error = error {
    print(error.localizedDescription)
    return
}

guard let authentication = user.authentication else { return }
let credential = FIRGoogleAuthProvider.credential(withIDToken: authentication.idToken,
                                                      accessToken: authentication.accessToken)



// Finished disconnecting user from the app succesfully if error is nil:
func sign(_ signIn: GIDSignIn!, didDisconnectWithUser user: GIDGoogleUser!,
                withError error: Error!) {
        // Perform any operations when the user disconnects from app here.
        // ...
}

yet I am still faced with the compile issue: 但我仍面临编译问题:

AppDelegate does not conform to protocol 'GIDSignInDelegate' AppDelegate不符合协议'GIDSignInDelegate'

在此输入图像描述

It looks like you defined the methods of that protocol outside of the AppDelegate class, so they are just global functions, not methods. 看起来您在AppDelegate之外定义了该协议的方法,因此它们只是全局函数,而不是方法。

You need to move them inside the } that closes AppDelegate (just above the first protocol method). 你需要在关闭AppDelegate}中移动它们(就在第一个协议方法之上)。

Tip : if you select all of the code in that file and press Ctrl+I Xcode will reindent your code which may make it easier to see what's going wrong. 提示 :如果您选择该文件中的所有代码并按Ctrl+I Xcode将重新启动您的代码,这样可以更容易地查看出现了什么问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM