简体   繁体   English

无法将类型“ AppDelegate”的值分配给类型“ GIDSignInDelegate!”

[英]Cannot assign value of type 'AppDelegate' to type 'GIDSignInDelegate!"

Cannot assign value of type 'AppDelegate' to type 'GIDSignInDelegate!' 无法将类型“ AppDelegate”的值分配给类型“ GIDSignInDelegate!”。

  • I have added both - #import #import in the Bridging header file. 我在桥接头文件中都添加了#import #import。
  • I have installed the google SDK from cocoapods '/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.2.0/lib/cocoapods.rb' 我已经从cocoapods'/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.2.0/lib/cocoapods.rb'安装了Google SDK
  • This is the AppDelegate declaration - class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInUIDelegate { 这是AppDelegate声明-AppDelegate类:UIResponder,UIApplicationDelegate,GIDSignInUIDelegate {

Step 2: Describe your environment 步骤2:描述您的环境

  • xcode 8 Xcode 8
  • iOS 10 iOS 10
Observed Results: 观察结果:
  • Compiler Error - Cannot assign value of type 'AppDelegate' to type 'GIDSignInDelegate!' 编译器错误-无法将类型“ AppDelegate”的值分配给类型“ GIDSignInDelegate!”。
Relevant Code: 相关代码:
 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. self.initialize() IQKeyboardManager.sharedManager().enable = true TimeSyncManager.sharedInstance.syncTimeWithServer(withNotifcationOption: false) AppScreenManager.sharedInstance.setUpInitialScreen() SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions) //setUpGoogleSDK() var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services: \\(configureError)") GIDSignIn.sharedInstance().delegate = self //<<--------Error at this Point application.registerForRemoteNotifications() UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in //Parse errors and track state } return true 

Now the problem I face is that Appdelegate shows error that- Type 'AppDelegate' does not conform to protocol 'GIDSignInDelegate' 现在我面临的问题是Appdelegate显示错误-类型'AppDelegate'不符合协议'GIDSignInDelegate'

My AppDelegate Code is 我的AppDelegate代码是

 class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate { var window: UIWindow? public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!){ } // Finished disconnecting |user| from the app successfully if |error| is |nil|. public func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!){ } } 

You have implemented GIDSignInUIDelegate instead of GIDSignInDelegate . 您已经实现了GIDSignInUIDelegate而不是GIDSignInDelegate Simply implement the GIDSignInDelegate will remove the compile error. 只需实现GIDSignInDelegate消除编译错误。

class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

Don't forgot to implement methods of GIDSignInDelegate with AppDelegate . 不要忘记使用AppDelegate实现GIDSignInDelegate方法。

func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {

}

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {

}

You need to implement GIDSignInDelegate in AppDelegate 您需要在AppDelegate中实现GIDSignInDelegate

 class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

  func googleSignIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {

  }


  func googleSignOut() {

  }

  // Implement the required GIDSignInDelegate methods and Unauth when disconnected from Google

  func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!, withError error: NSError!) {

  }


}

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

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