From 710283be08449d99e5fcb2ad4703580d18072293 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Mon, 30 Sep 2019 16:12:44 -0700 Subject: [PATCH 1/7] Fix Deprecated API Usage issue --- packages/google_sign_in/CHANGELOG.md | 4 ++++ packages/google_sign_in/ios/google_sign_in.podspec | 2 +- packages/google_sign_in/pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/google_sign_in/CHANGELOG.md b/packages/google_sign_in/CHANGELOG.md index b46be247f317..6b986c83242d 100644 --- a/packages/google_sign_in/CHANGELOG.md +++ b/packages/google_sign_in/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.0.10 + +* Update iOS CocoaPod dependency to 5.0 to fix deprecated API usage issue. + ## 4.0.9 * Update and migrate iOS example project. diff --git a/packages/google_sign_in/ios/google_sign_in.podspec b/packages/google_sign_in/ios/google_sign_in.podspec index 673341edfcf9..952fa7d59289 100755 --- a/packages/google_sign_in/ios/google_sign_in.podspec +++ b/packages/google_sign_in/ios/google_sign_in.podspec @@ -15,6 +15,6 @@ Enables Google Sign-In in Flutter apps. s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h' s.dependency 'Flutter' - s.dependency 'GoogleSignIn', '~> 4.0' + s.dependency 'GoogleSignIn', '~> 5.0' s.static_framework = true end diff --git a/packages/google_sign_in/pubspec.yaml b/packages/google_sign_in/pubspec.yaml index c5adc53f218d..73a607b0092d 100644 --- a/packages/google_sign_in/pubspec.yaml +++ b/packages/google_sign_in/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android and iOS. author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in -version: 4.0.9 +version: 4.0.10 flutter: plugin: From 9b7eac550e55751a7da62f471bf3da00deff9614 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Mon, 30 Sep 2019 16:43:34 -0700 Subject: [PATCH 2/7] Update to 5.0 compatibility --- .../ios/Classes/GoogleSignInPlugin.m | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m index 483bc5c6e81c..c035db531f40 100644 --- a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m +++ b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m @@ -29,7 +29,7 @@ details:error.localizedDescription]; } -@interface FLTGoogleSignInPlugin () +@interface FLTGoogleSignInPlugin () @end @implementation FLTGoogleSignInPlugin { @@ -49,8 +49,7 @@ - (instancetype)init { self = [super init]; if (self) { [GIDSignIn sharedInstance].delegate = self; - [GIDSignIn sharedInstance].uiDelegate = self; - + // On the iOS simulator, we get "Broken pipe" errors after sign-in for some // unknown reason. We can avoid crashing the app by ignoring them. signal(SIGPIPE, SIG_IGN); @@ -84,11 +83,15 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } } else if ([call.method isEqualToString:@"signInSilently"]) { if ([self setAccountRequest:result]) { - [[GIDSignIn sharedInstance] signInSilently]; + [[GIDSignIn sharedInstance] restorePreviousSignIn]; } } else if ([call.method isEqualToString:@"isSignedIn"]) { - result(@([[GIDSignIn sharedInstance] hasAuthInKeychain])); + result(@([[GIDSignIn sharedInstance] hasPreviousSignIn])); } else if ([call.method isEqualToString:@"signIn"]) { + // TODO(jackson): It might be more appropriate to use controller of the FlutterView + UIViewController *controller = [UIApplication sharedApplication].keyWindow.rootViewController; + [GIDSignIn sharedInstance].presentingViewController = controller; + if ([self setAccountRequest:result]) { @try { [[GIDSignIn sharedInstance] signIn]; @@ -136,9 +139,7 @@ - (BOOL)setAccountRequest:(FlutterResult)request { - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { NSString *sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey]; id annotation = options[UIApplicationOpenURLOptionsAnnotationKey]; - return [[GIDSignIn sharedInstance] handleURL:url - sourceApplication:sourceApplication - annotation:annotation]; + return [[GIDSignIn sharedInstance] handleURL:url]; } #pragma mark - protocol From 89187b50da6305b1e68b18be21138d44e9c50d70 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Mon, 30 Sep 2019 16:49:17 -0700 Subject: [PATCH 3/7] reformat --- packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m index c035db531f40..98168138e84d 100644 --- a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m +++ b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m @@ -49,7 +49,7 @@ - (instancetype)init { self = [super init]; if (self) { [GIDSignIn sharedInstance].delegate = self; - + // On the iOS simulator, we get "Broken pipe" errors after sign-in for some // unknown reason. We can avoid crashing the app by ignoring them. signal(SIGPIPE, SIG_IGN); From 46d23e36f7dad7d98e0791418c73e3ad3d36a49c Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Mon, 30 Sep 2019 17:23:17 -0700 Subject: [PATCH 4/7] Update to use [registrar messenger] --- packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m index 98168138e84d..a4f86a2d0a70 100644 --- a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m +++ b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m @@ -40,15 +40,16 @@ + (void)registerWithRegistrar:(NSObject *)registrar { FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/google_sign_in" binaryMessenger:[registrar messenger]]; - FLTGoogleSignInPlugin *instance = [[FLTGoogleSignInPlugin alloc] init]; + FLTGoogleSignInPlugin *instance = [[FLTGoogleSignInPlugin alloc] initWithController:[registrar messenger]]; [registrar addApplicationDelegate:instance]; [registrar addMethodCallDelegate:instance channel:channel]; } -- (instancetype)init { +- (instancetype)initWithController:(id)controller { self = [super init]; if (self) { [GIDSignIn sharedInstance].delegate = self; + [GIDSignIn sharedInstance].presentingViewController = controller; // On the iOS simulator, we get "Broken pipe" errors after sign-in for some // unknown reason. We can avoid crashing the app by ignoring them. @@ -88,10 +89,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } else if ([call.method isEqualToString:@"isSignedIn"]) { result(@([[GIDSignIn sharedInstance] hasPreviousSignIn])); } else if ([call.method isEqualToString:@"signIn"]) { - // TODO(jackson): It might be more appropriate to use controller of the FlutterView - UIViewController *controller = [UIApplication sharedApplication].keyWindow.rootViewController; - [GIDSignIn sharedInstance].presentingViewController = controller; - if ([self setAccountRequest:result]) { @try { [[GIDSignIn sharedInstance] signIn]; From 52ed349cb95cfb871eb663a09e7d0e5ca3c1475a Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Tue, 22 Oct 2019 16:47:51 -0700 Subject: [PATCH 5/7] Implement code review feedback --- .../ios/Classes/GoogleSignInPlugin.m | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m index a4f86a2d0a70..f77e4b8f3640 100644 --- a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m +++ b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m @@ -40,17 +40,16 @@ + (void)registerWithRegistrar:(NSObject *)registrar { FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/google_sign_in" binaryMessenger:[registrar messenger]]; - FLTGoogleSignInPlugin *instance = [[FLTGoogleSignInPlugin alloc] initWithController:[registrar messenger]]; + FLTGoogleSignInPlugin *instance = [[FLTGoogleSignInPlugin alloc] init]; [registrar addApplicationDelegate:instance]; [registrar addMethodCallDelegate:instance channel:channel]; } -- (instancetype)initWithController:(id)controller { +- (instancetype)init { self = [super init]; if (self) { [GIDSignIn sharedInstance].delegate = self; - [GIDSignIn sharedInstance].presentingViewController = controller; - + // On the iOS simulator, we get "Broken pipe" errors after sign-in for some // unknown reason. We can avoid crashing the app by ignoring them. signal(SIGPIPE, SIG_IGN); @@ -89,6 +88,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } else if ([call.method isEqualToString:@"isSignedIn"]) { result(@([[GIDSignIn sharedInstance] hasPreviousSignIn])); } else if ([call.method isEqualToString:@"signIn"]) { + [GIDSignIn sharedInstance].presentingViewController = [self topViewController]; + if ([self setAccountRequest:result]) { @try { [[GIDSignIn sharedInstance] signIn]; @@ -190,4 +191,36 @@ - (void)respondWithAccount:(id)account error:(NSError *)error { result(error != nil ? getFlutterError(error) : account); } +- (UIViewController *)topViewController { + return [self topViewControllerFromViewController:[UIApplication sharedApplication] + .keyWindow.rootViewController]; +} + +/** + * This method recursively iterate through the view hierarchy + * to return the top most view controller. + * + * It supports the following scenarios: + * + * - The view controller is presenting another view. + * - The view controller is a UINavigationController. + * - The view controller is a UITabBarController. + * + * @return The top most view controller. + */ +- (UIViewController *)topViewControllerFromViewController:(UIViewController *)viewController { + if ([viewController isKindOfClass:[UINavigationController class]]) { + UINavigationController *navigationController = (UINavigationController *)viewController; + return [self + topViewControllerFromViewController:[navigationController.viewControllers lastObject]]; + } + if ([viewController isKindOfClass:[UITabBarController class]]) { + UITabBarController *tabController = (UITabBarController *)viewController; + return [self topViewControllerFromViewController:tabController.selectedViewController]; + } + if (viewController.presentedViewController) { + return [self topViewControllerFromViewController:viewController.presentedViewController]; + } + return viewController; +} @end From 34abc18371e7f8091809e1c94a6deddb463e71fd Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Tue, 22 Oct 2019 16:49:23 -0700 Subject: [PATCH 6/7] Remove dead code --- packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m index f77e4b8f3640..dae35297500f 100644 --- a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m +++ b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m @@ -136,7 +136,6 @@ - (BOOL)setAccountRequest:(FlutterResult)request { - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { NSString *sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey]; - id annotation = options[UIApplicationOpenURLOptionsAnnotationKey]; return [[GIDSignIn sharedInstance] handleURL:url]; } From bb5c3eb34b4749158dd20c19fe750c0854059d7d Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Thu, 24 Oct 2019 18:40:53 -0700 Subject: [PATCH 7/7] format --- packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m index dae35297500f..716eb36585c4 100644 --- a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m +++ b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m @@ -49,7 +49,7 @@ - (instancetype)init { self = [super init]; if (self) { [GIDSignIn sharedInstance].delegate = self; - + // On the iOS simulator, we get "Broken pipe" errors after sign-in for some // unknown reason. We can avoid crashing the app by ignoring them. signal(SIGPIPE, SIG_IGN); @@ -192,7 +192,7 @@ - (void)respondWithAccount:(id)account error:(NSError *)error { - (UIViewController *)topViewController { return [self topViewControllerFromViewController:[UIApplication sharedApplication] - .keyWindow.rootViewController]; + .keyWindow.rootViewController]; } /** @@ -211,7 +211,7 @@ - (UIViewController *)topViewControllerFromViewController:(UIViewController *)vi if ([viewController isKindOfClass:[UINavigationController class]]) { UINavigationController *navigationController = (UINavigationController *)viewController; return [self - topViewControllerFromViewController:[navigationController.viewControllers lastObject]]; + topViewControllerFromViewController:[navigationController.viewControllers lastObject]]; } if ([viewController isKindOfClass:[UITabBarController class]]) { UITabBarController *tabController = (UITabBarController *)viewController;