|
13 | 13 | @author Sam Muggleworth (PointSource, LLC)
|
14 | 14 | */
|
15 | 15 |
|
16 |
| -// need to swap out a method, so swizzling it here |
17 |
| -static void swizzleMethod(Class class, SEL destinationSelector, SEL sourceSelector); |
18 | 16 |
|
19 |
| -@implementation AppDelegate (IdentityUrlHandling) |
| 17 | +@implementation GooglePlus |
20 | 18 |
|
21 |
| -+ (void)load { |
22 |
| - swizzleMethod([AppDelegate class], |
23 |
| - @selector(application:openURL:sourceApplication:annotation:), |
24 |
| - @selector(identity_application:openURL:sourceApplication:annotation:)); |
| 19 | +- (void)pluginInitialize |
| 20 | +{ |
| 21 | + NSLog(@"GooglePlus pluginInitizalize"); |
| 22 | + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:CDVPluginHandleOpenURLNotification object:nil]; |
| 23 | + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURLWithAppSourceAndAnnotation:) name:CDVPluginHandleOpenURLWithAppSourceAndAnnotationNotification object:nil]; |
25 | 24 |
|
26 |
| - swizzleMethod([AppDelegate class], |
27 |
| - @selector(application:openURL:options:), |
28 |
| - @selector(indentity_application_options:openURL:options:)); |
29 | 25 | }
|
30 | 26 |
|
31 |
| -/** Google Sign-In SDK |
32 |
| - @date July 19, 2015 |
33 |
| - */ |
34 |
| -- (BOOL)identity_application: (UIApplication *)application |
35 |
| - openURL: (NSURL *)url |
36 |
| - sourceApplication: (NSString *)sourceApplication |
37 |
| - annotation: (id)annotation { |
38 |
| - GooglePlus* gp = (GooglePlus*) [self.viewController pluginObjects][@"GooglePlus"]; |
39 |
| - |
40 |
| - if ([gp isSigningIn]) { |
41 |
| - gp.isSigningIn = NO; |
42 |
| - return [[GIDSignIn sharedInstance] handleURL:url sourceApplication:sourceApplication annotation:annotation]; |
43 |
| - } else { |
44 |
| - // call super |
45 |
| - return [self identity_application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; |
46 |
| - } |
| 27 | +- (void)handleOpenURL:(NSNotification*)notification |
| 28 | +{ |
| 29 | + |
| 30 | + // no need to handle this handler, we dont have an sourceApplication here, which is required by GIDSignIn handleURL |
| 31 | + |
47 | 32 | }
|
48 | 33 |
|
49 |
| -/** |
50 |
| -From https://github.com/EddyVerbruggen/cordova-plugin-googleplus/issues/227#issuecomment-227674026 |
51 |
| -Fixes issue with G+ login window not closing correctly on ios 9 |
52 |
| -*/ |
53 |
| -- (BOOL)indentity_application_options: (UIApplication *)app |
54 |
| - openURL: (NSURL *)url |
55 |
| - options: (NSDictionary *)options |
| 34 | +- (void)handleOpenURLWithAppSourceAndAnnotation:(NSNotification*)notification |
56 | 35 | {
|
57 |
| - GooglePlus* gp = (GooglePlus*) [self.viewController pluginObjects][@"GooglePlus"]; |
58 | 36 |
|
59 |
| - if ([gp isSigningIn]) { |
60 |
| - gp.isSigningIn = NO; |
61 |
| - return [[GIDSignIn sharedInstance] handleURL:url |
62 |
| - sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] |
63 |
| - annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]; |
64 |
| - } else { |
65 |
| - // Other |
66 |
| - return [self indentity_application_options:app openURL:url options:options]; |
| 37 | + NSMutableDictionary * options = [notification object]; |
| 38 | + |
| 39 | + NSURL* url = options[@"url"]; |
| 40 | + |
| 41 | + NSString* possibleReversedClientId = [url.absoluteString componentsSeparatedByString:@":"].firstObject; |
| 42 | + |
| 43 | + if ([possibleReversedClientId isEqualToString:self.getreversedClientId] && self.isSigningIn) { |
| 44 | + self.isSigningIn = NO; |
| 45 | + [[GIDSignIn sharedInstance] handleURL:url |
| 46 | + sourceApplication:options[@"sourceApplication"] |
| 47 | + annotation:options[@"annotation"]]; |
67 | 48 | }
|
68 | 49 | }
|
69 |
| -@end |
70 |
| - |
71 |
| -@implementation GooglePlus |
72 | 50 |
|
73 | 51 | // If this returns false, you better not call the login function because of likely app rejection by Apple,
|
74 | 52 | // see https://code.google.com/p/google-plus-platform/issues/detail?id=900
|
@@ -226,18 +204,4 @@ - (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)vie
|
226 | 204 | [self.viewController dismissViewControllerAnimated:YES completion:nil];
|
227 | 205 | }
|
228 | 206 |
|
229 |
| -#pragma mark Swizzling |
230 |
| - |
231 | 207 | @end
|
232 |
| - |
233 |
| -static void swizzleMethod(Class class, SEL destinationSelector, SEL sourceSelector) { |
234 |
| - Method destinationMethod = class_getInstanceMethod(class, destinationSelector); |
235 |
| - Method sourceMethod = class_getInstanceMethod(class, sourceSelector); |
236 |
| - |
237 |
| - // If the method doesn't exist, add it. If it does exist, replace it with the given implementation. |
238 |
| - if (class_addMethod(class, destinationSelector, method_getImplementation(sourceMethod), method_getTypeEncoding(sourceMethod))) { |
239 |
| - class_replaceMethod(class, destinationSelector, method_getImplementation(destinationMethod), method_getTypeEncoding(destinationMethod)); |
240 |
| - } else { |
241 |
| - method_exchangeImplementations(destinationMethod, sourceMethod); |
242 |
| - } |
243 |
| -} |
0 commit comments