2016-12-13 7 views
0

리더 보드 용 앱에서 Google Play 게임을 구현했습니다. 내 요구 사항은 사용자 로그인 사파리에서 처음으로 (로그인에 자동으로 사파리로 리디렉션) 때이 코드사용자를위한 Google Play 게임 확인이 로그인되어 있습니다.

[GPGManager sharedInstance].statusDelegate = self; 
BOOL isSignedIn = [[GPGManager sharedInstance] signInWithClientID:kGoogleClient silently:flag]; 
NSLOG(@“is signedin %d",[GPGManager sharedInstance].isSignedIn); 

하지만이 변수가 false를 반환 할 때마다 [GPGManager sharedInstance].isSignedIn를 작성했습니다

정보 경고를 표시하는 것입니다.

어떤 아이디어가 있습니까?

답변

0

GGLContext shared instance을 구성해야합니다. 앱의 여러 위치에서이 작업을 수행 할 수 있습니다. 이 인스턴스를 구성하는 가장 쉬운 장소는 앱 위임자의 application : didFinishLaunchingWithOptions : 메소드에 있습니다.

응용 프로그램 대리인의 .h 파일에서이 클래스가 GIDSignInDelegate 프로토콜을 구현한다고 선언하십시오. 앱 대리인의 application:didFinishLaunchingWithOptions에서

#import <Google/SignIn.h> 
@interface AppDelegate : UIResponder <UIApplicationDelegate, GIDSignInDelegate> 
AppDelegate.h 

: 방법의 GGLContext를 구성 인스턴스를 공유하고 로그인 대리자를 설정합니다.
- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    NSError* configureError; 
    [[GGLContext sharedInstance] configureWithError: &configureError]; 
    NSAssert(!configureError, @"Error configuring Google services: %@", configureError); 

    [GIDSignIn sharedInstance].delegate = self; 

    return YES; 
} 

앱 위임의 application:openURL:options: 방법을 구현합니다. 메서드는 GIDSignIn 인스턴스의 handleURL 메서드를 호출해야합니다.이 메서드는 인증 프로세스가 끝날 때 응용 프로그램이 수신하는 URL을 제대로 처리합니다.

- (void)signIn:(GIDSignIn *)signIn 
didSignInForUser:(GIDGoogleUser *)user 
    withError:(NSError *)error { 
    // Perform any operations on signed in user here. 
    NSString *userId = user.userID;     // For client-side use only! 
    NSString *idToken = user.authentication.idToken; // Safe to send to the server 
    NSString *fullName = user.profile.name; 
    NSString *givenName = user.profile.givenName; 
    NSString *familyName = user.profile.familyName; 
    NSString *email = user.profile.email; 
    // ... 
} 

- (void)signIn:(GIDSignIn *)signIn 
didDisconnectWithUser:(GIDGoogleUser *)user 
    withError:(NSError *)error { 
    // Perform any operations when the user disconnects from app here. 
    // ... 
} 
: 응용 프로그램의 위임에
- (BOOL)application:(UIApplication *)app 
      openURL:(NSURL *)url 
      options:(NSDictionary *)options { 
    return [[GIDSignIn sharedInstance] handleURL:url 
          sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] 
            annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]; 
} 

, 다음과 같은 방법을 정의하여 로그인 과정을 처리 할 수 ​​GIDSignInDelegate 프로토콜을 구현