gpt4 book ai didi

ios - GPPSignIn 委托(delegate)方法未被执行?

转载 作者:行者123 更新时间:2023-11-28 18:59:00 25 4
gpt4 key购买 nike

我已经按照谷歌网站上的说明将 Goolge+ signin 集成到 iOS(使用 ObjC),但是委托(delegate)方法(我对此方法感兴趣 finishedWithAuth:auth:error ) 的 GPPSignIn 没有被执行。我必须将委托(delegate)方法中收到的访问 token 存储在共享首选项中。

这是我的代码:

`

-(void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
NSLog(@"Received error %@ and auth object %@",error, auth);
if (error) {
NSLog(@"error");
} else {
NSLog(@"success");
}
}
- (BOOL)application: (UIApplication *)application
openURL: (NSURL *)url
sourceApplication: (NSString *)sourceApplication
annotation: (id)annotation {
NSLog(@"application");
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
-(void)refreshInterfaceBasedOnSignIn {
NSLog(@"refreshInterfaceBasedOnSignIn");
if ([[GPPSignIn sharedInstance] authentication]) {
// The user is signed in.
self.signInButton.hidden = YES;
[self readProfileInformation];
// Perform other actions here, such as showing a sign-out button
[self readProfileInformation];
NSLog(@"readProfileInformation");
} else {
self.signInButton.hidden = NO;
// Perform other actions here
}
}
- (void)disconnect {
[[GPPSignIn sharedInstance] disconnect];
}
- (void)didDisconnectWithError:(NSError *)error {
if (error) {
NSLog(@"Received error %@", error);
} else {
// The user is signed out and disconnected.
// Clean up user data as specified by the Google+ terms.
}
}
- (void)signOut {
[[GPPSignIn sharedInstance] signOut];
}
-(void)viewDidLoad
{
[super viewDidLoad];
// google+ code
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
// uncommented to fetch user email
signIn.shouldFetchGoogleUserEmail = YES;
// You previously set kClientId in the "Initialize the Google+ client" step
signIn.clientID = kClientId;
// Uncomment one of these two statements for the scope you chose in the previous step
// signIn.scopes = @[ kGTLAuthScopePlusLogin ];
// uncommented & set to "profile" & "email" scope:
signIn.scopes = @[ @"profile", @"email" ];
// Optional: declare signIn.actions, see "app activities"
signIn.delegate = self;
// try silent authentication
[signIn trySilentAuthentication];
}
@end

`

谢谢

最佳答案

这在我运行 iOS 8 的应用程序中也发生在我身上。这对我来说是在应用程序启动后立即在 AppDelegate 中设置 clientId,而不是在我的 UIViewController 类的 viewDidLoad 方法中设置,如 Google+ 中所示在以下 URL 中登录 iOS 示例:https://developers.google.com/+/mobile/ios/sign-in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/
//Google+
// Set app's client ID for |GPPSignIn| and |GPPShare|.
[GPPSignIn sharedInstance].clientID = @"xxxxxx.......apps.googleusercontent.com";

...

return YES;

}

因此,在您的 UIViewController 类中,登录方法应该是:

 - (void)viewDidLoad {
[super viewDidLoad];

//Google+ for Logging in the user again if the app has been authorized
signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserID = YES;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.scopes = @[ kGTLAuthScopePlusLogin ];
signIn.delegate = self;
[signIn trySilentAuthentication];

...
}

关于ios - GPPSignIn 委托(delegate)方法未被执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28470948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com