2015-06-16 9 views
8

का उपयोग कर किसी अन्य Google ऐप के साथ साइन इन करते समय Google उपयोगकर्ता को नहीं लाता है, मैं Google Sign-In for iOS का उपयोग कर रहा हूं और सिम्युलेटर का उपयोग करते समय यह ठीक काम कर रहा है क्योंकि कोई भी Google ऐप इंस्टॉल नहीं है और उपयोगकर्ता लाया जाता है, लेकिन जब मेरे आईफोन 6 डिवाइस का उपयोग करते हैं तो यूट्यूब ( में संभाल हस्ताक्षर के लिए उन्हें अंदर कुछ पंजीकृत खाते) के साथ के बाद, जब एप्लिकेशन कोड पर वापस आने के लिए इस समारोह पर प्रवेश नहीं करते:।GIDSignIn

-(void)signIn:(GIDSignIn *) signIn 
    didSignInForUser:(GIDGoogleUser *) 
    user withError:(NSError *) error 

किसी को भी मेरी मदद कर सकते मैं प्रवेश के लिए एक और समारोह उपयोग नहीं कर सकते मुझे [[GIDSignIn sharedIstance] signIn] पर कॉल करना होगा और यह फ़ंक्शन पता लगाएगा कि कोई अन्य Google ऐप इंस्टॉल है और स्वचालित रूप से एक और Google ऐप या वेबव्यू खोलता है।

+0

कोई भाग्य? मैं इसे काम करने के लिए नहीं मिल सकता .. – Chicken

+0

मुझे भी एक ही समस्या का सामना करना पड़ रहा है, अगर आपको वह जवाब मिल गया है तो कृपया मुझे यह बताएं कि इसे कैसे हल किया जाए। –

उत्तर

1
import UIKit 
import GoogleSignIn 
import Google 

class ViewController: UIViewController,GIDSignInUIDelegate, GIDSignInDelegate { 

override func viewDidLoad() { 
    super.viewDidLoad() 
    let gidSingIn = GIDSignIn() 

    GIDSignIn.sharedInstance().uiDelegate = self 
     gidSingIn.delegate = self 
    GIDSignIn.sharedInstance().delegate = self 

    var configureError:NSError? 
    GGLContext.sharedInstance().configureWithError(&configureError) 

    assert(configureError == nil, "Error configuring Google services: \(configureError)") 


    let button = GIDSignInButton(frame:CGRectMake(0,0,30, 200)) 
     button.center = self.view.center 
     button.backgroundColor = UIColor.blueColor() 
     self.view.addSubview(button) 



    // Do any additional setup after loading the view, typically from a nib. 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

@IBAction func signInGoogle(sender: AnyObject) { 

    print("pressed") 

} 

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, 
      withError error: NSError!) { 
    if (error == nil) { 
     // Perform any operations on signed in user here. 
     print(user.userID)    // For client-side use only! 
     print(user.authentication.idToken) // Safe to send to the server 
     print(user.profile.name) 
     print(user.profile.givenName) 
     print(user.profile.familyName) 
     print(user.profile.email) 
     print(user.authentication.accessToken) 
     print(user.profile) 
    } else { 
     print("\(error.localizedDescription)") 
    } 
} 
func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!, 
      withError error: NSError!) { 
} 

} // इस जीमेल googleplus के लिए नहीं खाते के साथ लॉगिन कर रहा है। बस अपने नियंत्रक के भीतर कॉपी और अतीत। और अपने AppDelegate कक्षा

func application(application: UIApplication, 
       openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { 
    var options: [String: AnyObject] = [UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication!,UIApplicationOpenURLOptionsAnnotationKey: annotation] 
    return GIDSignIn.sharedInstance().handleURL(url, 
               sourceApplication: sourceApplication, 
               annotation: annotation) 
} 
4

मैं ठीक से GIDSignIn उदाहरण के लिए कुछ गुण सेट करके समस्या का समाधान हो। उदाहरण के लिए:

GIDSignIn*sigNIn=[GIDSignIn sharedInstance]; 
[sigNIn setDelegate:self]; 
[sigNIn setUiDelegate:self]; 
sigNIn.shouldFetchBasicProfile = YES; 
sigNIn.allowsSignInWithBrowser = NO; 
sigNIn.allowsSignInWithWebView = YES; 
sigNIn.scopes = @[@"https://www.googleapis.com/auth/plus.login",@"https://www.googleapis.com/auth/userinfo.email",@"https://www.googleapis.com/auth/userinfo.profile"]; 
sigNIn.clientID [email protected]"xxxxxxxxxxxxxxxxxxxxxxxgai.apps.googleusercontent.com"; 
[sigNIn signIn]; 
2

मुझे लगता है कि आप अपने खुद के सर्वर जो आप अपने GIDSignin के साथ एक serverclientID शामिल करने के लिए की आवश्यकता है साथ GIDSignin उपयोग कर रहे हैं ग्रहण करने के लिए जा रहा हूँ। यह मेरे ऐप को वेबव्यू या यहां तक ​​कि ब्राउज़र खोलने के बजाय लॉग इन करने के लिए यूट्यूब या Google प्लस का उपयोग करने का प्रयास करेगा। यह एक GIDSigninError = -1 "संभावित रूप से पुनर्प्राप्त करने योग्य त्रुटि .." लौटाएगा और उपयोगकर्ता को लॉग इन करने की अनुमति नहीं देगा।

जिस तरह से मैंने इसे हल किया था, वह यूआईपीप्लिकेशंस को ओवरराइड करके खोले जाने से पहले Google या यूट्यूब से यूआरएल को अवरुद्ध कर रहा था canOpenURL समारोह। मैं UIApplication उपवर्गीकरण और इस तरह canOpenURL को लागू करने से ऐसा किया:

@interface MyApp : UIApplication 
- (BOOL)canOpenURL:(NSURL *)url; 
@end 

@implementation MyApp 
- (BOOL)canOpenURL:(NSURL *)url 
{ 
    if ([[url scheme] hasPrefix:@"com-google-gidconsent"] || [[url scheme] hasPrefix:@"com.google.gppconsent"]) { 
     return NO; 
    } 
    return [super canOpenURL:url]; 
} 
@end 

int main(int argc, char * argv[]) { 
    @autoreleasepool { 
     return UIApplicationMain(argc, argv, NSStringFromClass([MyApp class]), NSStringFromClass([AppDelegate class])); 
    } 
} 

सूचना है कि आमतौर पर वहाँ argv के बाद एक शून्य होगा, लेकिन यह वह जगह है जहाँ आप UIApplication के अपने उपवर्ग डाल दिया। यह भी है कि आप ऐपडिलेगेट के अपने उप-वर्ग का उपयोग कैसे कर सकते हैं।

अन्य समाधान UIApplication पर एक वर्ग है कि canOpenURL ओवरराइड करता है बना सकते हैं और swizzling उपयोग अपने कस्टम canOpenURL भीतर मूल कार्यान्वयन कॉल करने के लिए होगा। यह swizzling पर एक अच्छा लेख है: https://blog.newrelic.com/2014/04/16/right-way-to-swizzle/

हालांकि मैं आपको चेतावनी देता चाहिए, इन दो समाधान हैक्स कर रहे हैं और यदि आप ऐसा करने आपके आवेदन पर हो सकता है दुष्प्रभाव के बारे में वास्तव में सावधान रहना होगा। मुझे यकीन नहीं है कि सेब ठीक रहेगा।

0

में निम्नलिखित समारोह जोड़ने मेरे लिए मुद्दा यह था कि

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!)

अब और मौजूदा नहीं है, का उपयोग करने के बजाय

public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!)

अंतर नोट didSignInForUser बनाम didSignInFor। शायद एसडीके को स्विफ्ट करने के बाद अद्यतन करने के बाद 3.