Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
谷歌登录的正确iOS代码是什么_Ios_Objective C_Google Signin - Fatal编程技术网

谷歌登录的正确iOS代码是什么

谷歌登录的正确iOS代码是什么,ios,objective-c,google-signin,Ios,Objective C,Google Signin,我最近将我的GoogleSignin pod从3.x升级到4.1.1,并从这里链接文档: 请点击此处: 它们已经过时了 他们说进口是: #导入 它们有一些设置代码: NSError* configureError; [[GGLContext sharedInstance] configureWithError: &configureError]; NSAssert(!configureError, @"Error configuring Google services: %@", c

我最近将我的GoogleSignin pod从3.x升级到4.1.1,并从这里链接文档:

请点击此处:

它们已经过时了

  • 他们说进口是:
  • #导入

  • 它们有一些设置代码:

    NSError* configureError;
    [[GGLContext sharedInstance] configureWithError: &configureError];
    NSAssert(!configureError, @"Error configuring Google services: %@", configureError);
    
  • 那似乎过时了

    我找不到4.1.x特定文档


    (我的意思是,这个问题主要是为了让Google Identity更新文档。我知道答案,我将在下面发布)

    幸运的是,github示例repo得到了维护。根据这项承诺:

    正确的导入是:

    #导入

    (如果需要,也可以使用
    @import googlesign

    上下文
    似乎已被删除,因此应删除使用它的代码。似乎没有其他类似的东西需要取代它


    有了这两个变化,谷歌登录为我工作。

    下面是Pod文件的代码

    source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '10.2'
    use_frameworks!
    
    target ’App Target’ do
    pod 'GoogleSignIn'
    end
    
    然后在AppDelegate.swift文件中添加标题导入GoogleSignIn 然后
    func应用程序(application:UIApplication,didFinishLaunchingWithOptions launchOptions:[uiApplicationLaunchOptions:Any]?)->Bool{GIDSignIn.sharedInstance().clientID=“googlesigninclient id”;
    }

    现在在ViewController类中

    class LoginViewController:UIViewController 
    ,GIDSignInUIDelegate, GIDSignInDelegate { 
    
      //Add Button action for gmail login 
     @IBAction func loginWithGmail(_ sender: Any) {
    
        GIDSignIn.sharedInstance().signIn()
    
    
    }
    
    
     //deleage method will call after gmail login 
     func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, 
     withError error: Error!) {
         if (error == nil) {//login success
         } else {
          //login fail
         }
    
     }
    }
    
    class LoginViewController:UIViewController 
    ,GIDSignInUIDelegate, GIDSignInDelegate { 
    
      //Add Button action for gmail login 
     @IBAction func loginWithGmail(_ sender: Any) {
    
        GIDSignIn.sharedInstance().signIn()
    
    
    }
    
    
     //deleage method will call after gmail login 
     func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, 
     withError error: Error!) {
         if (error == nil) {//login success
         } else {
          //login fail
         }
    
     }
    }