ios - 谷歌使用google sdk登录ios?

标签 ios

@class GPPSignInButton;

我不想使用 GPPSignInButton 进行登录和身份验证,我想在按下时使用我的自定义按钮,然后登录过程将开始,并像 facebook 一样使用强制 webview 登录也可以在 Google+ 中登录吗? 就像“Using the OAuth 2 Controllers” 提前致谢

任何帮助将不胜感激。

最佳答案

是的,您可以使用任何 UIButton,而不是使用 GPPSignInButton。

使用以下方法在 viewDidLoad 中初始化 Google+ sdk:

 GPPSignIn *signIn = [GPPSignIn sharedInstance];
    signIn.shouldFetchGooglePlusUser = YES;
    signIn.shouldFetchGoogleUserEmail = YES;  // Uncomment to not get the user's email

    signIn.clientID = kClientId;

    signIn.scopes = [NSArray arrayWithObjects:kGTLAuthScopePlusMe,kGTLAuthScopePlusLogin, nil];
        signIn.delegate = self;

现在在 uibutton 操作中

- (IBAction)googlePlusSignIn:(id)sender
{
    GPPSignIn *signIn = [GPPSignIn sharedInstance];
    if([[GPPSignIn sharedInstance] authentication])
    {
        [signIn trySilentAuthentication];
    }
    else
    {
        // This is method that opens the G+ sign view
        [signIn authenticate];
    }
}

在 Targets -> Info -> URL Types 中添加 URL 类型和 URL 方案。

enter image description here 然后在App Delegate中添加以下内容

- (BOOL)application: (UIApplication *)application
            openURL: (NSURL *)url
  sourceApplication: (NSString *)sourceApplication
         annotation: (id)annotation {
    return [GPPURLHandler handleURL:url
                  sourceApplication:sourceApplication
                         annotation:annotation];
}

关于ios - 谷歌使用google sdk登录ios?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30906435/

相关文章:

ios - 如何访问不属于 iOS 主包的文件

ios - 使用 Swift 对日语字符进行排序

ios - 仅为 iPhone 6 Plus 禁用原始分辨率

ios - UISearchController 未在 UITableViewController 中搜索

ios - Swift 4 - 对成员 '>' (iOS 11) 的引用不明确

ios - UINavigationBar 的背景图片

JavascriptCore:从 native 代码执行 javascript 定义的回调函数

ios - Sprite 套件设置最小值。和最大。跳跃

ios - 分析 iOS Today Widget(仪器)

ios - 如何在swift 3中仅在按钮的有界区域上获取触摸事件