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;
しかし、この実装には私が理解できない何か問題があります。