Google+ SDK for iOS Add Signin button programmatically -


as g+ docs here: https://developers.google.com/+/mobile/ios/sign-in

the sign in button can added using xib or programmatically in uiviewcontroller.

i have tableviewcontroller , i'm going add g+ signin button accessory view of table row:

subtitlecell.accessoryview = self.googleplussigninbutton; 

where signin button going initialized follows:

-(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 gppsigninbutton class linked in because references     // 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];  } 

the button set @ viewdidload:

- (void)viewdidload {      [super viewdidload];      [self setgoogleplusbuttons];  //... 

the uiviewcontrolled has interface signin delegate:

@interface mxmsettingstableviewcontroller () <gppsignindelegate> @end 

it seems delegate not being called or shared sign in button not linked instance of controller:

// gppsignindelegate  - (void)finishedwithauth:(gtmoauth2authentication *)auth                    error:(nserror *)error {    ///.... } 

i assume

// make sure gppsigninbutton class linked in because references // xib file doesn't count. [gppsigninbutton class]; 

is linking viewcontroller instance button:

// button handles google+ sign-in. @property (retain, nonatomic) gppsigninbutton *googleplussigninbutton; 

but there wrong in implementation cannot figure out.

first of should call sign in method on action of googleplussigninbutton

so code should be:

-(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];      [googleplussigninbutton addtarget:self action:@selector(signingoogle:) forcontrolevents:uicontroleventtouchupinside]; } 

and sign in should way:

- (void)signingoogle {     gppsignin *signin = [gppsignin sharedinstance];     signin.delegate = self;     signin.shouldfetchgoogleuseremail = yes;     signin.clientid = kclientid;     signin.scopes = [nsarray arraywithobjects:kgtlauthscopepluslogin,nil];     signin.actions = [nsarray arraywithobjects:@"http://schemas.google.com/listenactivity",nil];     [signin authenticate]; } 

your code missing [signin authenticate]; call, plust need pass in clientid, in above snippet constant value (you need declare that)


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -