至于这里的 G+ 文档:https ://developers.google.com/+/mobile/ios/sign-in
可以使用 XIB 或以编程方式在 UIViewController 中添加登录按钮。
我有一个 TableViewController,我将添加 G+ 登录按钮作为表格行的附属视图:
subtitleCell.accessoryView = self.googlePlusSignInButton;
登录按钮将被初始化如下:
-(void) setGooglePlusButtons {
self.googlePlusSignInButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
UIImage *backgroundButtonImage = [UIImage imageNamed:@"bt_search_cancel.png"];
googlePlusSignInButton_.frame = CGRectMake(0.0f,
0.0f,
backgroundButtonImage.size.width,
backgroundButtonImage.size.height);
googlePlusSignInButton_.titleLabel.textColor = [UIColor whiteColor];
googlePlusSignInButton_.titleLabel.font = [UIFont boldSystemFontOfSize:11.0f];
googlePlusSignInButton_.titleLabel.numberOfLines = 2;
googlePlusSignInButton_.titleLabel.shadowColor = [UIColor darkGrayColor];
googlePlusSignInButton_.titleLabel.shadowOffset = CGSizeMake(0.0f,
-1.0f);
[googlePlusSignInButton_ setTitle:NSLocalizedString(@"UI_BUTTONS_LOGIN", @"")
forState:UIControlStateNormal];
[googlePlusSignInButton_ setBackgroundImage:backgroundButtonImage
forState:UIControlStateNormal];
// Make sure the GPPSignInButton class is linked in because references from
// xib file doesn't count.
[GPPSignInButton class];
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.delegate = self;
signIn.shouldFetchGoogleUserEmail = signIn.shouldFetchGoogleUserEmail;
signIn.actions = [NSArray arrayWithObjects:
@"http://schemas.google.com/ListenActivity",
nil];
}
该按钮在 viewDidLoad 处设置:
- (void)viewDidLoad {
[super viewDidLoad];
[self setGooglePlusButtons];
//...
UIViewControlled 有一个用于登录委托的接口:
@interface MXMSettingsTableViewController () <GPPSignInDelegate>
@end
似乎没有调用委托或共享登录按钮未链接到控制器的实例:
// GPPSignInDelegate
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
///....
}
我假设
// Make sure the GPPSignInButton class is linked in because references from
// xib file doesn't count.
[GPPSignInButton class];
正在链接 ViewController 实例按钮:
// The button that handles Google+ sign-in.
@property (retain, nonatomic) GPPSignInButton *googlePlusSignInButton;
但是我无法弄清楚这个实现有什么问题。