无法指定“AppDelegate”类型的值来键入“GIDSignInDelegate!”

时间:2017-03-16 08:48:15

标签: ios swift3 google-plus xcode8

无法指定“AppDelegate”类型的值来键入“GIDSignInDelegate!”

  • 我添加了两个 -    #进口    #进口 在Bridging头文件中。
  • 我已经安装了来自cocoapods的/ google SDK /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.2.0/lib/cocoapods.rb'
  • 这是AppDelegate声明 - class AppDelegate:UIResponder,UIApplicationDelegate,GIDSignInUIDelegate {

第2步:描述您的环境

  • xcode 8
  • iOS 10
观察结果:
  • 编译器错误 - 无法指定“AppDelegate”类型的值以键入“GIDSignInDelegate!”
相关守则:
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

现在我遇到的问题是Appdelegate显示错误 - 类型'AppDelegate'不符合协议'GIDSignInDelegate'

我的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!){

}
}

2 个答案:

答案 0 :(得分:3)

您已实施GIDSignInUIDelegate而非GIDSignInDelegate。只需实现GIDSignInDelegate将删除编译错误。

class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

不要忘记使用GIDSignInDelegate实现AppDelegate的方法。

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

}

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

}

答案 1 :(得分:1)

您需要在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!) {

  }


}
相关问题