PhoneGap GCM-|Cordova plugin - android

I use the following plugin: marknutter/GCM-Cordova from git hub.
I installed this plugin on eclipse and ran it on an android device.
I manage to register the device for GCM messages + receive messages.
When The device receives a message from Google Cloud, it calls the onMessage event handler, line 55, in this file:
https://github.com/marknutter/GCM-Cordova/blob/master/src/com/cordova2/gcm/GCMIntentService.java
The event handler reaches line 77 to run this command: GCMPlugin.sendJavascript( json );
this commands supposed to send the data received to the webView of the app.
However the static class' GCMPlugin members, are not initialized at all so, when the call to GCMPlugin.sendJavascript( json ) all the members of GCMPlugin members are null. As a result an exception occurs and the message can't be delivered to the webView.
Anyone has an idea how to fix this ?

I would not waste any time trying to run some obscure plug-ins, when there is officially supported PhoneGap plugin for push notifications: https://github.com/phonegap-build/PushPlugin. I'm using it in a couple of my apps already and it works wonders. Updates to it are pushed every couple of months.

If anyone is interested, I'm working on this plugin to support the latest Cordova and using the latest GCM from Google which will allow you to send push notifications to Android and iOS devices: https://github.com/gonzaloaune/GCMPushPlugin

Related

Amazon Pinpoint and Ionic - Push notifications not working when app is in background

I was asked to develop a sample app integrated with Amazon Pinpoint. Since I am not a pro at developing apps, I decided to follow this simple tutorial and develop the app following the steps described in it. The only differences are that, instead of using an emulator, I executed the project in my own cell phone (a Xiaomi Redmi 4x) and instead of GCM, I used Firebase.
At first, it seemed to work perfectly, but when I moved the app to the background and went back to my homescreen, I could no more receive push notifications from my app. When the app is open and running, everytime I send a push notification a pop-up appears with Title "New Notification" and buttons "Ignore"/"View". But when in background, nothing is visible in my system tray!
Also, if someone knows which part of the code is responsible for this notifications, just warn me and I upload it here.
Okay, so after some tests I made it work (not through console, but through CLI). To do so, I followed some steps I found this question, that took me to two other documents: one from Amazon teaching how to send push notifications through CLI and a simple but very detailed tutorial of phonegap-plugin, the plugin used in our Ionic application to process the pushes.
First of all, replace the phonegap-plugin in your app with the master version avaliable in the github link I sent you.
Then, putting all those information together, I figured out how to write a .json file containing the information we need to send the pushes. Here is a sample of the code I used:
{
"MessageRequest": {
"Addresses": {
"YOUR_DEVICE_ADDRESS_HERE": {
"ChannelType": "GCM"
}
},
"MessageConfiguration": {
"GCMMessage": {
"RawContent": "{\"data\":{\"title\":\"StackOverflow rocks!\",\"body\":\"Am I right?\",\"actions\":[ { \"title\":\"Yes!\", \"callback\":\"app.yes\", \"foreground\":true }, { \"title\":\"No!\", \"callback\":\"app.no\", \"foreground\":false }]}}"
}
}
}
}
As you can see, to change the content in the push notificationm, you'll have to edit it's "RawContent". To do so, use the phonegap-plugin tutorial I sent you and find out how to do the alterations you wish.
Last step: once you updated your plugin version AND saved the code above in a .json file (let's call it test.json), you can send it to your phone oppening command line in the folder containing your .json and writting:
aws pinpoint send-messages --color on --region YOUR_SERVICE_REGION --cli-input-json file:///test.json
This should do the trick! Hope it works for you. If any doubts, just let me know!

GCM errors in the logcat

I'm running the official GCM sample on a Samsung S6 with 6.0.1
https://github.com/googlesamples/google-services/tree/master/android/gcm
I've gone through all the steps to make it work, registering in Google Cloud Console, adding the json file, etc.
I am able to send messages with GcmSender (included in the sample) and the app on the device receives them, but:
Every time the app receives a message, there are these two errors in the logcat:
FirebaseInstanceId E Failed to resolve target intent service, skipping classname enforcement
E Error while delivering the message: ServiceIntent not found.
Maybe they can be ignored (the app does get the pushed messages), but they have severity = Error, what if there is a good reason for this?
What if this causes GCM to work unreliably (some sort of "exponential backoff")?
What causes them? How can I make it so that these errors do not happen?
Since the official word is that GCM will be supported going forward for existing apps -- I'd like to avoid Firebase messaging.
GCM seems easier to set up and has fewer "magical bits" all around (all the various services / registrations / tokens / APIs and what not). I just need reliable cloud driven push messaging and that's it, nothing else.
So the question is not "should I be using GCM or Firebase", I know the "correct" answer to that.
It's "when running the official GCM sample there are these errors in the logcat, what are they and how can I fix them".
Finally, the app's manifest:
https://github.com/googlesamples/google-services/blob/master/android/gcm/app/src/main/AndroidManifest.xml
and the relevant bits of build.gradle:
```dependencies {
compile 'com.google.android.gms:play-services-gcm:9.2.1'
...
}
apply plugin: 'com.google.gms.google-services'
```

Push notification from Mixpanel dashboard to Android Cordova app

I am successfully sending Push Notifications from the Mixpanel Dashboard to a Cordova app on both iOS and Android devices, using phonegap-plugin-push.
However, the title and body values entered in the default fields only appear on iOS devices.
For the notification to appear on Android devices, I currently need to include a custom payload in Mixpanels "Custom Data":
{
"title":"Title for Android only",
"body":"Content for Android only"
}
This is an error prone step for any non-technical using Mixpanel to send notifications.
Does someone know an easier way to do this?
The short answer here is that Cordova/Phonegap and similar third party frameworks are not 100% optimized for Mixpanel functionality (although they work pretty great), and as such you'll need to generate separate push notifications for both iOS and Android in your Mixpanel project.
Providing context, all iOS pushes regardless of app deliver a JSON payload to APN using the same keys to deliver their messages (alert, badge, sound). However, the keys that Android apps process for incoming GCM pushes are entirely dependent on how the GCM receiver is established, and therein lies the problem here.
Mixpanel's Android SDK initializes pushes and uses a GCM receiver that is specific to Mixpanel messages, and fully expects its custom keys (mp_message, mp_title) in order to render the notification. The webapp reformats the message input to meet these key requirements (http://bit.ly/1OGgU1y)
However, the Phonegap GCM receiver expects different keys as you've noticed. I'd recommend referring to the phonegap github page in order to get more context into the expected push format and behavior (looks like they expect "title" and "message" as the keys): http://bit.ly/1KDScye
Unfortunately, what this means is that the Android app is not optimized to receive the default, web-app generated Mixpanel pushes, although your iOS one is. Mixpanel's SDKs are intended to maximize capabilities for that platform, and it isn't guaranteed that Cordova or similar JS frameworks will translate 100%.
So to conclude - Creating a message in the Mixpanel push editor will send to iOS, but for Android you'll need to use the custom JSON payload in a separate notification, including keys that the phonegap GCM receiver is compatible with.
If its help to anyone this is how I solved the problem
in phonegap-plugin-push
you need to modify two files
GCMIntentService.java
private String normalizeKey(String key) {
if (key.equals(BODY) || key.equals(ALERT) || key.equals(MP_MESSAGE) || key.equals(GCM_NOTIFICATION_BODY)) { // added MP_MESSAGE
PushConstants.java
public static final String MP_MESSAGE = "mp_message";

Azure notification hub cross platform push

I need to send a push notification to mobile devices that have registered on my notification hub.
The hub is set up to allow windows phone, apple and android devices to register, and I have the appropriate keys and certificates in place. (According to the documentation!)
I am using the latest release of the Microsoft.Azure.NotificationHubs namespace, version 2.16, as advised by the NuGet package manager.
I want to send one message, to all registrations as well as sending a message to a specific device. I can see the devices have all registered correctly with the hub, and have tags that allow me to send notifications to them.
I am trying to use the SendDirectNotificationAsync() method
that takes a Dictionary and a string tag as parameters.
I have also tried the SendNotificationAsync() method that takes a Notification object as a parameter.
Neither method causes a notification to appear on my windows phone with the parameters I have provided, so without an example or more information from the help files, I am stuck.
I cannot find any current examples using these methods and classes.
The examples I have found pre-date the release, and do not show what to send to the notification hub for a cross platform notification to work.
I know these have only just been released, but any help / guidance would be appreciated, as I have reached a complete dead-end with this.
Just a quick update...
Although I never got this to work as I wanted to (as described above), what I ended up doing was to use each platforms native notification as below;
var result1 = await hub.SendMpnsNativeNotificationAsync(windowstoast, mobileDeviceId);
var result2 = await hub.SendGcmNativeNotificationAsync(androidToast, mobileDeviceId);
var result3 = await hub.SendAppleNativeNotificationAsync(iOStoast, mobileDeviceId);
The 'toast' was formatted as per the individual platforms requirements in the documentation.
The 'mobileDeviceId' was the tag that each device registered with the notification hub.
So, clumsy, but it works reliably to achieve the same end.
I still would like to get the cross platform way to work though. Will look into it a bit more when I have time.

Cordova app that doesn't use push notifications: "Missing push notification entitlement"

We've got a Cordova based iOS app that does not use push notifications. As of Cordova 3.5.0, each submission we have made to the app store results in an email informing us that our app includes API used to register with Apple's Push Notification Service, but doesn't have push notification entitlement.
The app has been accepted each time, as we don't actually use push notifications for anything. However, I would like to avoid triggering this warning in case Apple decides to change their policy as to whether these API references are acceptable.
We did not experience the issue with prior versions of Cordova, and have done no work in Objective-C ourselves. Is this a known issue with Cordova 3.5? Searching has yielded some folks with similar problems but I've only found solutions for people wanting to add push entitlements, (rather than figure out where the Push API is being referenced and remove it). I took a look at the Cordova issues ML, but didn't find anything there. Any other leads that folks are aware of would be appreciated!
Plugins used:
org.apache.cordova.console
org.apache.cordova.device
org.apache.cordova.file
org.apache.cordova.inappbrowser
org.apache.cordova.media
org.apache.cordova.network-information
org.apache.cordova.splashscreen
Relevant email snippet, specific info replaced with [ ]:
From: iTunes Store
Date: Wed, Sep 17, 2014 at 3:49 PM
Subject: iTunes Connect: Your app "[appName]" (Apple ID: [id]) has one or more issues
To: [developer]
Dear developer,
We have discovered one or more issues with your recent delivery for "[app]". Your delivery was successful, but you may wish to correct the following issues in your next delivery:
Missing Push Notification Entitlement - Your app appears to include API used to register with the Apple Push Notification service, but the app signature's entitlements do not include the "aps-environment" entitlement. If your app uses the Apple Push Notification service, make sure your App ID is enabled for Push Notification in the Provisioning Portal, and resubmit after signing your app with a Distribution provisioning profile that includes the "aps-environment" entitlement. See "Provisioning and Development" in the Local and Push Notification Programming Guide for more information. If your app does not use the Apple Push Notification service, no action is required. You may remove the API from future submissions to stop this warning. If you use a third-party framework, you may need to contact the developer for information on removing the API.
After you’ve corrected the issues, you can use Xcode or Application Loader to upload a new binary to iTunes Connect.
Regards,
The App Store team
HOW TO DO THIS VIA THE XCODE UI (6.1):
While commenting out the offending code in Classes\AppDelegate.m will get your app approved, you want to continue benefitting from future Cordova upgrades so the best way to do this is to turn on the DISABLE_PUSH_NOTIFICATIONS symbol during compilation so this bit of code gets left out.
I come from a C# background so I understand conditional compilation but I am new to XCode so I had to do a bit of research finding out how to define compilation symbols via the UI.
Turns out the magic words are 'Preprocessor Macro'. This is how the you can accomplish this graphically (note that this the way its done in XCode 6.1):
Hope this helps other people out there in same situation.
Krik is right ! I've found this API calls in /Classes/AppDelegate.m certainly generated by Cordova 3.5.
I din't tried it for the moment, but these lines can certainly be commented in xCode to avoid Apple's warnings.
- (void) application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// re-post ( broadcast )
NSString* token = [[[[deviceToken description]
stringByReplacingOccurrencesOfString: #"<" withString: #""]
stringByReplacingOccurrencesOfString: #">" withString: #""]
stringByReplacingOccurrencesOfString: #" " withString: #""];
[[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotification object:token];
}
- (void) application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
// re-post ( broadcast )
[[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotificationError object:error];
}
Have you had the Push Plugin installed at some point? Sounds like you have the respective Code somewhere in your application package. I'd do a project-wide search for the specific API calls e.g:
didRegisterForRemoteNotificationsWithDeviceToken
didFailToRegisterForRemoteNotificationsWithError
The dead code, files need to be removed.
Heres' the full documentation: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW2
As Charles Merriam points out, newer versions of cordova-ios make it easy to disable touching push notifications by setting the preprocesor flag DISABLE_PUSH_NOTIFICATIONS. (See bug history.)
You will need to cordova platform update ios, platform uninstall ios and platform install ios to get the new in AppDelegate.m. (Maybe there's a better way than blowing away the folder?)
I found a Cordova on_platform_add hook script that will edit project.pbxproj with that flag for you when you install the iOS platform. I needed to npm install xcode to get the hook script to work.
Both kirk and r121 are correct.
In more recent versions of Cordova, this offending code is now helpfully generated inside a wrapper of #ifndef DISABLE_PUSH_NOTIFICATIONS. All you need do is add-DISABLE_PUSH_NOTIFICATIONS to your compiler flags. That's set in target/Build Settings/Custom Compiler Flags/(both C and C++ release) for those building inside XCode.
In our build process, we have been blowing away and rebuilding the AppDelegate.m file a lot. The hack I use is:
sed -i "" -e "s/ifndef DISABLE_PUSH_NOTIFICATIONS/if 0/" build/cordova/platforms/ios/gThrive/Classes/AppDelegate.m
# That uses the os/x sed to not have push notifications in the app
which just makes the problem go away.

Categories

Resources