2013-09-04 11 views
7

chodzi o G + docs tutaj: https://developers.google.com/+/mobile/ios/sign-inGoogle+ SDK dla iOS przycisk Dodaj signin programowo

Znak w przycisk może być dodany używając XIB lub programowo w UIViewController.

Mam TableViewController i mam zamiar dodać przycisk G + signin jako akcesorium widzenia wierszu tabeli:

subtitleCell.accessoryView = self.googlePlusSignInButton; 

gdzie przycisk signin zostanie zainicjowany w następujący sposób:

-(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]; 

} 

przycisk jest ustawiony na viewDidLoad:

- (void)viewDidLoad { 

    [super viewDidLoad]; 

    [self setGooglePlusButtons]; 

//... 

UIViewControll ed posiada interfejs dla delegata signin:

@interface MXMSettingsTableViewController() <GPPSignInDelegate> 
@end 

Wydaje się, że pełnomocnik nie jest nazywany lub udostępniony znak w przycisk nie jest powiązany z instancji kontrolera:

// GPPSignInDelegate 

- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth 
        error:(NSError *)error { 
    ///.... 
} 

zakładam że

// Make sure the GPPSignInButton class is linked in because references from 
// xib file doesn't count. 
[GPPSignInButton class]; 

jest łączący przycisk wystąpienia ViewController:

// The button that handles Google+ sign-in. 
@property (retain, nonatomic) GPPSignInButton *googlePlusSignInButton; 

ale jest coś złego w tej implementacji, którego nie mogę wymyślić.

Odpowiedz

15

Przede wszystkim należy zadzwonić do podpisania w metodzie na działanie Twojego googlePlusSignInButton

więc kod powinien być:

-(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]; 
} 

i znak w powinny być w ten sposób:

- (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]; 
} 

Twój kod nie zawierał połączenia [signIn authenticate];, musisz też podać swój identyfikator klienta, który w powyższym fragmencie jest wartością stałą (musisz to zadeklarować)

+1

Tak, oczywiście !!!W ten sposób mogłem także oddzielić ten widok od obiektu "kontroler", który obsługuje konto G + i loginu (gdzie tutaj brakuje integracji kClient Id). Wielkie dzięki! – loretoparisi

+0

Dziwna rzecz. Aplikacja GooglePlus otwiera się, ale nie jest wykonywane uwierzytelnianie ani aplikacja openURL: (NSURL *) url sourceApplication: jest wywoływana. Identyfikator klienta jest poprawnie skonfigurowany w konsoli programisty. – loretoparisi

+1

Czy dodałeś typ adresu URL? Oto krok 4 tego przewodnika: https://developers.google.com/+/mobile/ios/getting-started – Lefteris

0

Pomimo kilku rozwiązań nie było sposobu, aby silentAuthentication dostać pracę

- (void)initialize { 
    // Read Google+ deep-link data. 
    [GPPDeepLink setDelegate:self]; 
    [GPPDeepLink readDeepLinkAfterInstall]; 

    // Setup Google+ share dialog. 
    [GPPShare sharedInstance].delegate = self; 

    // Setup Google+ signin 
    [GPPSignIn sharedInstance].clientID = APP_GOOGLEPLUS_APPID; 
    [GPPSignIn sharedInstance].delegate = self; 

    [GPPSignIn sharedInstance].shouldFetchGoogleUserEmail = YES; 
    [GPPSignIn sharedInstance].shouldFetchGoogleUserID = YES; 

    [GPPSignIn sharedInstance].actions = [NSArray arrayWithObjects:[self momentSchemaByType:MXMGooglePlusMomentListen], nil]; 

    [GPPSignIn sharedInstance].scopes = [NSArray arrayWithObjects:kGTLAuthScopePlusLogin, nil]; // defined in GTLPlusConstants.h 

    [[GPPSignIn sharedInstance] trySilentAuthentication]; 

    shareAfterLogin= NO; 
    trackIdToShare = nil; 

    if([[MXMLogger sharedLogger] isDebug]) { 
     NSLog(@"MXMGooglePlusManager initialize login %d keychain %d", [self isGooglePlusLoggedin], [GPPSignIn sharedInstance].hasAuthInKeychain); 
    } 
} 

Najdziwniejsze, keychain ma uwierzytelniania w

2013-09-13 13:01:35.849 musiXmatch[1090:790b] MXMGooglePlusManager initialize login 0 keychain 1 

ale konto nie jest zalogowany

Co do dokumentów tutaj

https://developers.google.com/+/mobile/ios/api/interface_g_p_p_sign_in

wdrożenie powinno być poprawne.

Powiązane problemy