Skip to content

Commit 3947eba

Browse files
collinjacksonmormih
authored andcommitted
[google_sign_in] Fix deprecated API usage issue by upgrading CocoaPod to 5.0 (flutter#2127)
* Fix Deprecated API Usage issue * Update to 5.0 compatibility
1 parent 8e9f2a2 commit 3947eba

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

packages/google_sign_in/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.0.11
2+
3+
* Update iOS CocoaPod dependency to 5.0 to fix deprecated API usage issue.
4+
15
## 4.0.10
26

37
* Remove AndroidX warning.

packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
details:error.localizedDescription];
3030
}
3131

32-
@interface FLTGoogleSignInPlugin () <GIDSignInDelegate, GIDSignInUIDelegate>
32+
@interface FLTGoogleSignInPlugin () <GIDSignInDelegate>
3333
@end
3434

3535
@implementation FLTGoogleSignInPlugin {
@@ -49,7 +49,6 @@ - (instancetype)init {
4949
self = [super init];
5050
if (self) {
5151
[GIDSignIn sharedInstance].delegate = self;
52-
[GIDSignIn sharedInstance].uiDelegate = self;
5352

5453
// On the iOS simulator, we get "Broken pipe" errors after sign-in for some
5554
// unknown reason. We can avoid crashing the app by ignoring them.
@@ -84,11 +83,13 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
8483
}
8584
} else if ([call.method isEqualToString:@"signInSilently"]) {
8685
if ([self setAccountRequest:result]) {
87-
[[GIDSignIn sharedInstance] signInSilently];
86+
[[GIDSignIn sharedInstance] restorePreviousSignIn];
8887
}
8988
} else if ([call.method isEqualToString:@"isSignedIn"]) {
90-
result(@([[GIDSignIn sharedInstance] hasAuthInKeychain]));
89+
result(@([[GIDSignIn sharedInstance] hasPreviousSignIn]));
9190
} else if ([call.method isEqualToString:@"signIn"]) {
91+
[GIDSignIn sharedInstance].presentingViewController = [self topViewController];
92+
9293
if ([self setAccountRequest:result]) {
9394
@try {
9495
[[GIDSignIn sharedInstance] signIn];
@@ -135,10 +136,7 @@ - (BOOL)setAccountRequest:(FlutterResult)request {
135136

136137
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
137138
NSString *sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey];
138-
id annotation = options[UIApplicationOpenURLOptionsAnnotationKey];
139-
return [[GIDSignIn sharedInstance] handleURL:url
140-
sourceApplication:sourceApplication
141-
annotation:annotation];
139+
return [[GIDSignIn sharedInstance] handleURL:url];
142140
}
143141

144142
#pragma mark - <GIDSignInUIDelegate> protocol
@@ -192,4 +190,36 @@ - (void)respondWithAccount:(id)account error:(NSError *)error {
192190
result(error != nil ? getFlutterError(error) : account);
193191
}
194192

193+
- (UIViewController *)topViewController {
194+
return [self topViewControllerFromViewController:[UIApplication sharedApplication]
195+
.keyWindow.rootViewController];
196+
}
197+
198+
/**
199+
* This method recursively iterate through the view hierarchy
200+
* to return the top most view controller.
201+
*
202+
* It supports the following scenarios:
203+
*
204+
* - The view controller is presenting another view.
205+
* - The view controller is a UINavigationController.
206+
* - The view controller is a UITabBarController.
207+
*
208+
* @return The top most view controller.
209+
*/
210+
- (UIViewController *)topViewControllerFromViewController:(UIViewController *)viewController {
211+
if ([viewController isKindOfClass:[UINavigationController class]]) {
212+
UINavigationController *navigationController = (UINavigationController *)viewController;
213+
return [self
214+
topViewControllerFromViewController:[navigationController.viewControllers lastObject]];
215+
}
216+
if ([viewController isKindOfClass:[UITabBarController class]]) {
217+
UITabBarController *tabController = (UITabBarController *)viewController;
218+
return [self topViewControllerFromViewController:tabController.selectedViewController];
219+
}
220+
if (viewController.presentedViewController) {
221+
return [self topViewControllerFromViewController:viewController.presentedViewController];
222+
}
223+
return viewController;
224+
}
195225
@end

packages/google_sign_in/ios/google_sign_in.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Enables Google Sign-In in Flutter apps.
1515
s.source_files = 'Classes/**/*'
1616
s.public_header_files = 'Classes/**/*.h'
1717
s.dependency 'Flutter'
18-
s.dependency 'GoogleSignIn', '~> 4.0'
18+
s.dependency 'GoogleSignIn', '~> 5.0'
1919
s.static_framework = true
2020

2121
s.platform = :ios, '8.0'

packages/google_sign_in/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system
33
for signing in with a Google account on Android and iOS.
44
author: Flutter Team <[email protected]>
55
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in
6-
version: 4.0.10
6+
version: 4.0.11
77

88
flutter:
99
plugin:

0 commit comments

Comments
 (0)