Updated to Cordova 2.7, fixed a number of bugs. Cleaned up some code.#5
Conversation
* Put all the plugin code in the plugin namespace: com.plugin.gcm; * Renamed to namespace GCM to gcm, namespaces should be lower case according to the java style guidelines; * Deleted the google gcm code and added gcm.jar instead; * Added CordovaGCMBroadcastReceiver.java to enable GCMIntentService to be namespaced in the plugin namespace instead of the client project (which is is the default with google's GCMIntentService); * Moved all java <--> javascript interop to PushPlugin; * Moved all notification code to GCMIntentService (maybe this fits better in its own class); * Changed the way the plugin detects cold starts in order for it not to crash when the back button is used to navigate out of the app; * Changed the caching on the filesystem to a memory cache on a static variable, which increases performance and simplifies code; * Cut up some code into separate methods ; * Added code comments; * Updated the readme file.
|
Thanks so much for your submission. Looks like a lot of work. I do have a few questions before I dig in any deeper.
Thanks again! |
|
1.) There are a few changes in the AndroidManifest due to the namespace renaming I did. I've also updated the plugin config file to reflect these changes. That's the only thing that's changed from the client code's perspective. Cold start, background and foreground contexts still operate the same. Just to be sure we're on the same page: The cold start flag is set when the application had to recreate the main activity with the cordova plugin. Technically this can happen when the application is still active in the background due to unloading of the activity by the OS. Foreground happens when the app is active and no notification is sent. 2.) I have no idea of PBG's infrastructure, but I guess adding support for different plugin versions with different cordova versions seems like a reasonable thing to do? 3.) The main issue was that under some circumstances you could get a "the application stopped working" message when re-entering the application after the main activity (and the PushPlugin) were unloaded. This happens when you click the back button out of your app, or when the app is cleaned up while running in the background to reclaim resources for other apps. This can only occur if you don't unregister your push messages on exit, (which is what you want when you want the application to send you messages even after it exited). The other bugs are probably just cordova 2.7 issues (although I'm not sure, I didn't use this library beforehand), and bugs caused by my refactoring process. |
|
@gsmeets why did you change the namespacing of the classes? if i update just the source, i don't want to have to change the manifest.xml and would think it should just work |
|
This is awesome work. We like it so much, in fact, that we have a PushNotification.js binding with JSNI in a library of our own (Pilot, version 2.7 is not out yet). And I've been trying to test it, but PushPlugin.java extends from Plugin, which is not found in cordova-2.7.0.jar, and thus I have a compile-time error in my project. I see a CordovaPlugin, but not a plain Plugin class. I installed this plugin in my Android project using plugman, so I grabbed the latest code from GitHub when I installed it. Other than the project not yet fully compatible with Cordova 2.7, I am not sure what else could be missing. Thoughts? Thanks! |
|
@dlamotta This is because Cordova 2.7 changed the name of the base class on which all plugins derive. Why not just change all our plugins to extend CordovaPlugin, you ask (and I'm glad you did)? PhoneGap Build necessarily supports versions of Cordova older than 2.7. Thus 'fixing' the plugin for 2.7 will break it for all of our customers who still build their apps on older versions of Cordova. We can get away with supporting 2.7 AND older versions on our Build servers because we have control of our own tooling. For manual builds, however, you will need to either build against an older version or Cordova, OR modify PushPlugin.java to extend "CordovaPlugin" instead of "Plugin". So instead of; You need; for 2.7+ HTH |
Updated to Cordova 2.7, fixed a number of bugs. Cleaned up some code.
|
@bobeast Thanks for the reply. Ok, that's interesting, so manual build folks will run into this problem when using Cordova 2.7. I started going down the path of replacing 'Plugin' with 'CordovaPlugin', but the changes were deeper than that. I'll take another look at it tonight. Thanks again. |
|
@dlamotta be sure and re-sync up to master. I am now extending CordovaPlugin since users will increasingly build against 2.7.0 and above. Let me know how it goes. |
|
@bobeast awesome. Even better! Thanks. |
|
Hi, Please remove me from your mailing list I am getting flooded :) Thanks, On 6/5/2013 3:02 PM, Bob Easterday wrote:
|
Fix didRegisterForRemoteNotification on iOS8
according to the java style guidelines;
be namespaced in the plugin namespace instead of the client project
(which is is the default with google's GCMIntentService);
better in its own class);
crash when the back button is used to navigate out of the app;
variable, which increases performance and simplifies code;