2013-09-04 6 views
7

जोड़े जी + डॉक्स यहाँ के रूप में: https://developers.google.com/+/mobile/ios/sign-inगूगल + एसडीके प्रवेश बटन प्रोग्राम के रूप में

प्रवेश करें बटन को एक XIB या प्रोग्राम के रूप में एक UIViewController में का उपयोग कर जोड़ा जा सकता है।

मैं एक TableViewController है और मैं एक तालिका पंक्ति के गौण दृश्य के रूप में जी + प्रवेश बटन जोड़ने के लिए जा रहा हूँ:

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

//... 

UIViewControll एड साइन इन प्रतिनिधि के लिए एक इंटरफेस है:

@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 उदाहरण बटन लिंक हो रहा है 0

लेकिन इस कार्यान्वयन में कुछ गड़बड़ है जिसे मैं समझ नहीं सकता।

उत्तर

15

सबसे पहले आप की कार्रवाई पर विधि साइन इन बुलाना चाहिए अपने 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]; 

    [googlePlusSignInButton addTarget:self action:@selector(signInGoogle:) forControlEvents:UIControlEventTouchUpInside]; 
} 

और संकेत में इस तरह से किया जाना चाहिए:

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

आपके कोड में [signIn authenticate]; कॉल गुम है, तो आपको अपने क्लाइंट आईडी में भी पास करने की आवश्यकता है, जो उपरोक्त स्निपेट में निरंतर मूल्य है (आपको इसे घोषित करने की आवश्यकता है)

+1

हां बिल्कुल !!!इस तरह से मैं इस दृश्य को "नियंत्रक" ऑब्जेक्ट से अलग करने में सक्षम था जो जी + खाता और लॉगिन (जहां के क्लाइंट आईडी आईडी एकीकरण गायब है) को संभाला जा रहा है। आपका बहुत बहुत धन्यवाद! – loretoparisi

+0

अजीब चीज। GooglePlus ऐप खुलता है लेकिन कोई लेख नहीं किया जाता है और न ही एप्लिकेशन openURL: (NSURL *) url स्रोत एप्लिकेशन: कहा जा रहा है। क्लाइंट आईडी सही डेवलपर कंसोल पर कॉन्फ़िगर किया गया है। – loretoparisi

+1

क्या आपने यूआरएल प्रकार जोड़ा है? यह मार्गदर्शिका में चरण 4 है: https://developers.google.com/+/mobile/ios/getting-started – Lefteris

0

कई समाधान के बावजूद वहाँ silentAuthentication बनाने के लिए कोई रास्ता नहीं काम कर रहा

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

अजीब बात करने के लिए किया गया था, कीचेन

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

में प्रमाणीकरण है, लेकिन खाते में प्रवेश न होने पर

यहां दस्तावेज़ों के लिए

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

कार्यान्वयन सही होना चाहिए।

संबंधित मुद्दे