菜鸟教程小白 发表于 2022-12-13 03:39:22

ios - Google 登录的正确 iOS 代码是什么


                                            <p><p>我最近将我的 GoogleSignin pod 从 3.x 更新到了 4.1.1,并从此处链接了文档:</p>
<p> <a href="https://developers.google.com/identity/sign-in/ios/sdk/" rel="noreferrer noopener nofollow">https://developers.google.com/identity/sign-in/ios/sdk/</a> </p>
<p>去这里:</p>
<p> <a href="https://developers.google.com/identity/sign-in/ios/sign-in" rel="noreferrer noopener nofollow">https://developers.google.com/identity/sign-in/ios/sign-in</a> </p>
<p>已经过时了。</p>
<ol>
<li>他们说进口是:</li>
</ol>
<p><code>#import <Google/SignIn.h></code></p>
<ol 开始=“2”>
<li><p>他们有一些设置代码:</p>
<pre><code> NSError* configureError;
[ configureWithError: &amp;configureError];
NSAssert(!configureError, @&#34;Error configuring Google services: %@&#34;, configureError);
</code></pre>
</li>
</ol>
<p>这似乎已经过时了。</p>
<p>我找不到 4.1.x 的特定文档。</p>
<p>(我的意思是这个问题主要是为了让 Google Identity 更新文档。我知道答案,我将在下面发布)</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>Pod 文件的波纹管代码</p>

<pre><code>source &#39;https://github.com/CocoaPods/Specs.git&#39;
platform :ios, &#39;10.2&#39;
use_frameworks!

target ’App Target’ do
pod &#39;GoogleSignIn&#39;
end
</code></pre>

<p>然后在 AppDelegate.swift 文件中添加 Header <strong>import GoogleSignIn</strong>
那么<br/>
<code>func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: ?) -> Bool { GIDSignIn.sharedInstance().clientID = "googlesigninclient id";
}</code></p>

<pre><code>func application(_ app: UIApplication, open url: URL, options:
= [:]) -&gt; Bool {
    return GIDSignIn.sharedInstance().handle(url,
                                             sourceApplication:
options as?
String,
                                                annotation:
options)
}
</code></pre>

<p>现在在 ViewController 类中</p>

<pre><code>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
   }

}
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Google 登录的正确 iOS 代码是什么,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/47796040/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/47796040/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Google 登录的正确 iOS 代码是什么