sah*_*108 20 ios ios8-share-extension google-signin share-extension
我正在尝试为我的应用程序创建共享扩展,这需要从扩展程序登录Google.我已经设置了共享组密钥链,并且能够从主应用程序写入并读取扩展目标.但我无法从扩展程序登录Google,因为GIDSignIn.sharedInstance().hasAuthInKeychain()始终返回false.
有没有办法从扩展程序登录Google,我该怎么做?任何帮助,将不胜感激.
import <GoogleSignIn/GoogleSignIn.h>
import <Google/Core.h>
Run Code Online (Sandbox Code Playgroud)
import Google
Run Code Online (Sandbox Code Playgroud)
在application:didFinishLaunchingWithOptionslaunchOptions:配置GGLContext对象中:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
GIDSignIn.sharedInstance().clientID = "client id"
GIDSignIn.sharedInstance.shouldFetchBasicProfile = true
GIDSignIn.sharedInstance().delegate = self
}
Run Code Online (Sandbox Code Playgroud)
然后,GIDSignInButton向您的应用程序添加视图。
最后,在视图控制器中,实现signIn:didSignInForUser:将在登录按钮tapped:授权应用程序时调用的委托方法。
- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error {
// Perform any operations on signed in user here.
// ...
}
Run Code Online (Sandbox Code Playgroud)
当您登录时,Google 框架必须使用本机 iOS 方法将新凭据添加到 iOS 钥匙串。因此,他们将使用SecItemAdd(_:_:)将一个或多个项目添加到钥匙串的方法。
要在应用程序和扩展程序中访问相同的钥匙串项目,您需要从项目设置中Xcode 的功能部分为应用程序和扩展程序启用“钥匙串共享” 。当您这样做时,Xcode 可能想要更新您的应用程序 ID 和配置文件,因为它们需要反映这个新功能。您可能需要重新授权应用程序(第 2 步)才能将凭据放入正确的组中。
Apple 文档明确指出:
如果您希望在多个应用程序之间共享新的钥匙串项,请在属性字典中包含 kSecAttrAccessGroup 键。此密钥的值必须是将共享此项目的所有程序所属的钥匙串访问组的名称。
当您使用 Xcode 创建应用程序时,Xcode 会向应用程序包添加 应用程序标识符权利。Keychain Services 使用此权利授予应用程序访问其自己的钥匙串项目的权限。您还可以 向应用程序添加钥匙串访问组权利,并在权利属性列表文件中指定应用程序所属的钥匙串访问组数组。
请参阅“适用于 iOS 的 Google 登录”。这是要使用的示例代码GIDSignIn:
GIDSignIn共享实例的引用:GIDSignIn *signIn = [GIDSignIn sharedInstance];[signIn setScopes:[NSArray arrayWithObject:@"https://www.googleapis.com/auth/plus.login"]];[signIn setDelegate:self];signIn:didSignInForUser:withError:。handleURL从application:openUrl:...调用共享实例。signIn共享实例;| 归档时间: |
|
| 查看次数: |
608 次 |
| 最近记录: |