2016-12-13 10 views
0

私はリーダーボードのために自分のアプリでGoogle Playゲームを実装しています。 私の要件は、ユーザーのログインSafariで初めて(ログインのために自動的にサファリにリダイレクト)するとき、私はこのコードユーザーの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を設定するインスタンスを共有し、サインインデリゲートを設定します。

アプリデリゲートのメソッド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プロトコルを実装

関連する問題