2

I asked iOS: Sign In with Google button yesterday and still struggling. The answer I got helped me figure out that the GooglePlus.bundle was imported incorrectly.

Now I am stuck on the part that the button that I created via XIB file, doesn't shows up on the page.

What I did?
I added a new button as per this gist, and validated if everything works fine. The code looks like

- (void)viewDidLoad {
    [super viewDidLoad];

    GPPSignInButton *button = [[GPPSignInButton alloc] init];
    [button setStyle:kGPPSignInButtonStyleWide];
    [self.view addSubview:button];

    GPPSignIn *signIn = [GPPSignIn sharedInstance];
    signIn.shouldFetchGooglePlusUser = YES;
    signIn.shouldFetchGoogleUserEmail = YES;


    [self.signInButton setStyle:kGPPSignInButtonStyleWide];


    signIn.clientID = kClientId;
    signIn.scopes = @[@"profile"];
    signIn.delegate = self;
//    [signIn trySilentAuthentication];

}

When I run it, I see
enter image description here

So button added manually works, but not the one I created with xib. My xib looks like
enter image description here

and in GooglePlusLoginViewController.h the code looks like

#import <UIKit/UIKit.h>
#import <GooglePlus/GooglePlus.h>

@class GPPSignInButton;

@interface GooglePlusLoginViewController : UIViewController <GPPSignInDelegate>
@property(weak, nonatomic) IBOutlet GPPSignInButton *signInButton;
@end

I want to learn what mistake I am doing, can someone spot that?

Thanks

1
  • did you add GPPSignInButton to your button in Class in identity inspector??
    – Mohit
    Jul 1, 2014 at 13:45

2 Answers 2

1

This is a bad way to do it. If you look at your output closely, the blue button still remains in the background. This is because, you have added UIButton in your storyboard/xib and you've hooked them up in your ViewController.h file.

Then you are creating new instance of GPPSignInButton and adding it back into the UIButton you've previously created.

You should not create button within button.

Btw, I ran into the same problem today, and here is how I solved it.

I programmatically created GPPSignInButton and positioned it programmatically within the view.

Add this in your viewDidLoad in your ViewController.m

GPPSignInButton *button = [[GPPSignInButton alloc] init];
[button setStyle:kGPPSignInButtonStyleWide];

CGRect frame = button.frame;
frame.origin.x = 50;
frame.origin.y = 190;
button.frame = frame;

[self.view addSubview:button];
0

Being new to iOS, I am not sure if this is the correct practice, but the following changes that I did worked for me

- (void)viewDidLoad {
    [super viewDidLoad];

    GPPSignInButton *button = [[GPPSignInButton alloc] init];
    [button setStyle:kGPPSignInButtonStyleWide];
    [self.signInButton addSubview:button];

    GPPSignIn *signIn = [GPPSignIn sharedInstance];
    signIn.shouldFetchGooglePlusUser = YES;
    signIn.shouldFetchGoogleUserEmail = YES;

    signIn.clientID = kClientId;
    signIn.scopes = @[@"profile"];
    signIn.delegate = self;
    [signIn trySilentAuthentication];

}

and it showed up as
enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.