[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[google_sign_in] Fix deprecated API usage issue by upgrading CocoaPod to 5.0 #2127

Merged
merged 10 commits into from
Oct 29, 2019
4 changes: 4 additions & 0 deletions packages/google_sign_in/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
47 changes: 39 additions & 8 deletions packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
details:error.localizedDescription];
}

@interface FLTGoogleSignInPlugin () <GIDSignInDelegate, GIDSignInUIDelegate>
@interface FLTGoogleSignInPlugin () <GIDSignInDelegate>
@end

@implementation FLTGoogleSignInPlugin {
Expand All @@ -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);
Expand Down Expand Up @@ -84,11 +83,13 @@ - (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"]) {
[GIDSignIn sharedInstance].presentingViewController = [self topViewController];

if ([self setAccountRequest:result]) {
@try {
[[GIDSignIn sharedInstance] signIn];
Expand Down Expand Up @@ -136,9 +137,7 @@ - (BOOL)setAccountRequest:(FlutterResult)request {
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
NSString *sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey];
id annotation = options[UIApplicationOpenURLOptionsAnnotationKey];
collinjackson marked this conversation as resolved.
Show resolved Hide resolved
return [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
return [[GIDSignIn sharedInstance] handleURL:url];
}

#pragma mark - <GIDSignInUIDelegate> protocol
Expand Down Expand Up @@ -192,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
2 changes: 1 addition & 1 deletion packages/google_sign_in/ios/google_sign_in.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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

s.platform = :ios, '8.0'
Expand Down
2 changes: 1 addition & 1 deletion packages/google_sign_in/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in
version: 4.0.9
version: 4.0.10
Copy link
@Knupper Knupper Oct 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we not update the version to 5.x.x as well to indicate wich GoogleSignIn Version is used inside?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we don't update the Dart and wrapped SDK versions in lockstep. In this case, we're not making a breaking change to the semantics of the Dart plugin, so I don't think a major version increment is needed.


flutter:
plugin:
Expand Down