針對iOS端集成Google登錄
1、引用pod庫
pod 'GoogleSignIn', '~> 6.0.0'
如安裝失敗
可先更新本地索引 pod repo update
國內(nèi)pod install最近失敗頻率較多,多試幾次
也可切換下源嘗試
# source 'https://cdn.cocoapods.org/'
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/aliyun/aliyun-specs.git'
2、配置 URL Types

image.png
3、初始化Google單例
signInConfig = [[GIDConfiguration alloc] initWithClientID:@"YOUR_IOS_CLIENT_ID"];
4、處理身份驗證重定向網(wǎng)址
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handled;
handled = [GIDSignIn.sharedInstance handleURL:url];
if (handled) {
return YES;
}
// Handle other custom URL types.
// If not handled by this app, return NO.
return NO;
}
5、嘗試恢復(fù)用戶的登錄狀態(tài)
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GIDSignIn.sharedInstance restorePreviousSignInWithCallback:^(GIDGoogleUser * _Nullable user,
NSError * _Nullable error) {
if (error) {
// Show the app's signed-out state.
} else {
// Show the app's signed-in state.
}
}];
return YES;
}
6、Google Login及Block
[GIDSignIn.sharedInstance signInWithConfiguration:signInConfig
presentingViewController:self
callback:^(GIDGoogleUser * _Nullable user,
NSError * _Nullable error) {
if (error) {
return;
}
// If sign in succeeded, display the app's main content View.
}];
7、Google Logout
[GIDSignIn.sharedInstance signOut];