Google Plus登录以获取Xcode共享扩展名 [英] Google plus sign-in for xcode share extension

查看:96
本文介绍了Google Plus登录以获取Xcode共享扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个iOS应用程序,以通过电子邮件共享网页链接,作为其中的一部分,我希望用户能够登录google plus.按照下面的说明,我已经使包含应用程序正常运行:

I’m writing an iOS app to share web page links by email, and as part of it I want users to be able to sign in to google plus. I’ve got the containing app working fine using the instructions from here:

https://developers.google.com/+/mobile/ios/登录

,现在我正尝试添加一个共享扩展名,该扩展名也可以访问用户的google +个人资料.我首先尝试将登录按钮添加到共享扩展程序中,但我认为这行不通,因为单击该按钮后,您被带出了应用程序,进入了浏览器以接受许可,然后无法重定向回共享扩展名(或者至少我看不到任何方法).

and now I’m trying to add a share extension that can also access the user’s google+ profile. I started off by trying to add the sign in button in to the share extension, but I don’t think that’s going to work because after clicking the button you’re taken out of the app to the browser to accept permissions, and then there’s no way to redirect back to the share extension (or at least I can’t see a way).

我现在希望用户可以登录并接受主(包含)应用程序中的权限,但是稍后再使用共享扩展名,并且仍然可以使用相同的配置文件登录.我在共享扩展中使用了自定义UIViewController,并且第一次尝试在共享扩展中使用与包含应用程序相同的客户端ID,并在viewDidLoad方法中调用它:

What I’m hoping now is that it’s possible for the user to sign in and accept permissions in the main (containing) app, but to then later use the share extension, and still be signed in with the same profile. I’m using a custom UIViewController in the share extension, and as a first attempt I’ve tried to use the same client id in the share extension as the containing app and to call this in the viewDidLoad method:

GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.clientID = kClientID;
signIn.scopes = @[ @"profile" ];
signIn.delegate = self;
if ([signIn hasAuthInKeychain]) {
    NSLog(@"Has auth in keychain");
} else {
    NSLog(@"No auth in keychain");
}

在包含应用程序的hasAuthInKeychain中返回true,但在共享扩展名中返回false.我正在使用的客户端ID绑定到主应用程序的捆绑包,因此我不确定是否应该能够在共享扩展中使用它,但是如果我尝试为共享创建单独的客户端ID扩展,那么大概我需要再次进行授权过程?

in the containing app hasAuthInKeychain returns true, but in the share extension it’s false. The client id that I’m using is tied to the bundle for main app, so I’m not sure if I should be able to use it in the share extension anyway, but if I tried to create a separate client id for the share extension then presumably I’d need to go through the authorisation process again?

是否可以通过主应用访问现有的身份验证令牌并在共享扩展中使用它?

Is there a way that I can get access to the existing auth token from the main app and use it in the share extension?

推荐答案

您在正确的轨道上.

要在应用程序和扩展程序中访问相同的钥匙串,需要在Xcode中为它们两者都启用钥匙串共享"功能.当您执行此操作时,Xcode可能要更新您的应用ID和配置文件,因为它们需要反映新功能.

To access the same keychain in both the app and the extension, you need to enable the "Keychain Sharing" capability for both of them in Xcode. When you do this, Xcode will probably want to update your app ID and provisioning profiles, because they need to reflect the new capability.

这是否足够取决于Google框架如何处理钥匙串.这完全是您需要的所有东西,因为作为 SecItemAdd的文档指示,默认情况下,项目将添加到列出的第一个组中.但是我不知道Google的代码是如何工作的,所以我不确定.

Whether this is enough depends on how the Google framework handles the keychain, though. It's probably all you need, because as the docs for SecItemAdd indicate, items will be added to the first listed group by default. But I don't know how Google's code works so I can't be certain of that.

执行此操作后,可能必须重新授权该应用程序才能将凭据放入正确的组中.不过,此后,应用程序和扩展程序都可以查找现有值.

Once you do this, you'll probably have to reauthorize the app to get the credentials into the right group. After that though, both app and extension can look up existing values.

这篇关于Google Plus登录以获取Xcode共享扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆