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 프로토콜을 구현