Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit 75f37a7

Browse files
Merge pull request #507 from kdgm/fix-handle-multiple-url-types
Fix handle multiple url types
2 parents b3bd4ad + 439a4c1 commit 75f37a7

File tree

1 file changed

+23
-59
lines changed

1 file changed

+23
-59
lines changed

src/ios/GooglePlus.m

+23-59
Original file line numberDiff line numberDiff line change
@@ -13,62 +13,40 @@
1313
@author Sam Muggleworth (PointSource, LLC)
1414
*/
1515

16-
// need to swap out a method, so swizzling it here
17-
static void swizzleMethod(Class class, SEL destinationSelector, SEL sourceSelector);
1816

19-
@implementation AppDelegate (IdentityUrlHandling)
17+
@implementation GooglePlus
2018

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];
2524

26-
swizzleMethod([AppDelegate class],
27-
@selector(application:openURL:options:),
28-
@selector(indentity_application_options:openURL:options:));
2925
}
3026

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+
4732
}
4833

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
5635
{
57-
GooglePlus* gp = (GooglePlus*) [self.viewController pluginObjects][@"GooglePlus"];
5836

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"]];
6748
}
6849
}
69-
@end
70-
71-
@implementation GooglePlus
7250

7351
// If this returns false, you better not call the login function because of likely app rejection by Apple,
7452
// see https://code.google.com/p/google-plus-platform/issues/detail?id=900
@@ -226,18 +204,4 @@ - (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)vie
226204
[self.viewController dismissViewControllerAnimated:YES completion:nil];
227205
}
228206

229-
#pragma mark Swizzling
230-
231207
@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

Comments
 (0)