在应用原生共享对话框中 google+ 登录 iOS

In app native share dialog and google+ signin in iOS

我想通过来自 google+ 的 inApp 本机共享对话框进行共享,但如文档中所述,它需要 google 登录。但我不想提供单独的 google 相同的登录按钮。那么,是否可以转到 safari 进行 google+ 登录(如果尚未登录),然后返回到应用程序并在应用程序中打开共享对话框?

此外,我需要知道 google+ ios sdk 中的哪个函数处理静默身份验证,从而为我提供编写应用内原生共享对话框代码的地方?

找到解决方案:

  1. 点击分享按钮时:

检查是否已经登录。这是由 sdk 处理的,但需要这样做:

GPPSignIn *signIn = [GPPSignIn sharedInstance];
[signIn authenticate];

signIn.shouldFetchGooglePlusUser = YES;


signIn.scopes = @[ kGTLAuthScopePlusLogin ];  // "https://www.googleapis.com/auth/plus.login" scope

// Optional: declare signIn.actions, see "app activities"
signIn.delegate = self;

现在,如果应用首次未获批准,我们会看到它重定向到 safari google+ 登录。应用通过后,通过delegate方法重定向回应用,实现原生分享对话框:

- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
               error: (NSError *) error {
id<GPPShareBuilder> shareBuilder = [[GPPShare sharedInstance] nativeShareDialog];

// Set any prefilled text that you might want to suggest
[shareBuilder setPrefillText:@"Please visit http://abcd.in to view my listing"];

[shareBuilder setURLToShare:[NSURL URLWithString:@"http://abcd.in"]];

[shareBuilder open];
NSLog(@"Received error %@ and auth object %@",error, auth);
}