cabotdeveloper / CordovaPlugin-GooglePlusWithDemoApp

This Repository contains the Cordova plugin for Google Plus integration. Also it is a project that implemented this plugin.
MIT License
7 stars 5 forks source link

Handling of redirect URL after authentication not implemented in plugin ... (yet?) #2

Open visionscaper opened 10 years ago

visionscaper commented 10 years ago

Hello,

Thank you for sharing this plugin.

I was trying to use your plugin in an iOS app and managed Google+ to correctly redirect back to the app after authentication. However, I found that handling of the redirect URL was completely missing from the plugin.

In the entry point to the app (in AppDelegate.m): -(BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication: (NSString *)sourceApplication annotation: (id)annotation { ... }

... the redirect URL needs to be handled. However, the default functionality of Cordova that is called in this entry point:

[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];

... only provides the means to propagate the url (or is expected to only provide the url), and not the sourceApplication and the annotation, while this is required to handle the url:

[GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];

So, I solved it as follows. In the entry point to the app, I added:

GoogleConnectPlugin* gcp = (GoogleConnectPlugin*)[[self.viewController pluginObjects] objectForKey:@"GoogleConnectPlugin"];

if ([gcp isSigningIn]) {
    [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];
}

... and subsequently added functionality to the plugin to keep the isSigningIn state.

Was I missing something, or do you maybe have a better solution in mind?

Thanks in advance!

-- Freddy