1

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

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

4

1 回答 1

2

找到了解决方案:

  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+ 登录。批准应用程序后,它会使用委托方法重定向到应用程序,其中可以实现本机共享对话框:

- (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);
}
于 2015-01-12T11:20:50.250 回答