Azure -> Easy api in Node.js-> how to send android push notifications? - android

We are using azure easy API (node.js) for our mobile app. We have set up notification hubs already and have tested them - they all seem to be working. However, we are not sure how to invoke these notification hubs within the easy API - we have followed the entire documentation provided by Microsoft (e.g.: http://azure.microsoft.com/en-us/documentation/articles/notification-hubs-nodejs-how-to-use-notification-hubs/) and have tried out multiple things.
Can someone point to examples / code snippets on how to send push notifications specifically from Easy API?
thanks
Sankar

As for your situation, you could follow the steps below to achieve your purpose.
Once your notification hub is set up, go to the Settings menu for
your App Service and click on the Easy APIs option. Click on the +
Add button and fill in the form.
Click on the API and then click on Edit script. This will open Visual Studio Online. This will allow you to edit the script online.
edit notification.js file with following content:
var azure = require('azure-sb');
module.exports = {
"post": function (req, res, next) {
var hubname = 'yourhubname';
var connectionstring = 'yourconnectingstring';
var notificationHubService = azure.createNotificationHubService(hubname, connectionstring);
var payload = {
data: {
message: 'Hello!'
}
};
notificationHubService.gcm.send(null, payload, function(error) {
if(!error) {
res.status(200).send('succ');
}
});
}
};
Note: Replace your own hubname and connectionstring above.
Install azure-sb module through Kudu. Go back to the Azure Portal, select your App Servcie, then Tools, followed by Kudu. Click on the PowerShell version of the Debug console.
Change directory into site/wwwroot, then type the following into the console:
npm install –-save azure-sb
test your easy API by Postman:
Eventually, your client device will receive the notification:
Help it helps. Any further concern, please feel free to let me know.

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!

Install hybrid not showing the opt-in notification message

I have a hybrid app in my QA environment and we don't see the opt in notification message on any device when the app is install.. This work on my local machine that uses my local eclipse MFP..
I expect to see the prompt:
"Rand jobs Would like to sent you notification
Notification may include alert, sound
these can be configured in Settings
Dont't Allow| OK
Can you please provide some hints on how to get this working again.. No phone are getting register...
I verify that certs and port are open..
Thanks
Are you using the same physical device during development and QA, and the same application ID?
This may be the issue: Reset push notification settings for app
The steps to reset iOS to recognize the app as a new app with push requests:
Delete your app from the device.
Turn the device off completely and turn it back on.
Go to Settings > General > Date & Time and set the date ahead a day or more.
Turn the device off completely again and turn it back on.
Use the WL.Server.sendMessage method. The appName and options parameters are
mandatory.
Specify the tagNames as an array in the options.target.tagNames object. In
Example, the tagNames sent in the procedure are in a loop to fill the
options.target.tagNames array.
Specify the message to be sent as text in options.message.alert.
For example :
function submitNotification(appName, tagNames, message)
{
var options = {};
options.message = {};
options.message.alert = message;
options.target = {};
options.target.tagNames = [];
for(var i=0; i<tagNames.length; i++){
options.target.tagNames.push(tagNames[i]);
}
var delayTimeOut = WL.Server.sendMessage(appName, options);
WL.Logger.warn("notificationTimeout"+delayTimeOut);
}
source Book:
Extending IBM Business
Process Manager to the Mobile
Enterprise with IBM Worklight

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.

Google Cloud Messaging not working with Phonegap

I'm having a lot of trouble to get Google Cloud Messaging to work in my Phonegap-based app.
I'm following the instructions that are here.
It uses the PushPlugin, which I installed in my app according to the instructions.
Somehow I get no response after registering, nothing happens (no console.log appears) when I do :
window.plugins.pushNotification.register(
pushSuccessHandler,
pushErrorHandler, {
"senderID":"12345678",
"ecb":"onNotificationGCM"
}
);
var pushSuccessHandler = function(result) {
console.log(result);
};
var pushErrorHandler = function(error) {
console.log(error);
};
var onNotificationGCM = function(e) {
console.log(e);
switch(e.event) {
case 'registered' : {
console.log('android reg id: ' + e.regid);
break;
}
}
};
I setup an API project in Google Developer Console, got a project number that I used as the SenderID, and did all modifications to the Phonegap manifest and config xml files.
My app is not published yet in the Play store.
Is this necessary to get Cloud Messaging working?
And is the code above enough to get a 'reg id', or do I first need to push something from the server, but with what 'reg id' then??
Somewhere I read that the push notifications only work in a Phonegap-app when it is running, or when the notification is clicked, so not when the app is started from the normal icon. I don't understand this however, because aren't the notifications supposed to work when the app is not running?
Push notification will work without publishing, publishing is not required.
Only you have to get Sender ID from developer console.
Sender Id - its project number in developer console
for more detail you can check here
https://github.com/phonegap-build/PushPlugin
I am using it its woreking fine for both android and iOS
Update:
I'm using Intellij IDEA to build the app. When I compiled with phonegap build android the push notifications were working ok.
I had to add the 'android-support-v13.jar' and 'gcm.jar' files as a library in the Project Settings of the IDEA project, to get it working. These libraries need to be added to the Dependencies of the main module with scope 'Compile'.
Before I only added them directly in Dependencies of the module, with Scope 'Provided' but apparently that doesn't work (although it compiled).

Push Messages for PhoneGap

I created an app for iPhone and Android using Phonegap.
Now I wanted to add push functionality which already works pretty good.
When a push message arrives on my iPhone I get a message on the homescreen. If I swipe it, iOS will open my application. - So far so good.
Now, within my PhoneGap app I need to check what that message actually says in order to open the correct view within my app via JavaScript.
I know there are quite some posts about this but I couldn't find some clear answers to these questions:
Does PhoneGap support push messages?
If yes, where is the documentation for that?
If not, which plugins/frameworks can be recommended? So far I found pushwoosh and Urbanair. Are they any good?
Regarding Pushwoosh, I noticed that I need some kind of pushwoosh ID - Why that?
By Pushwoosh ID you most probably mean Pushwoosh App Id or Application Code. It's an ID of your application in Pushwoosh Control Panel (current format is XXXXX-XXXXX). You will see it as soon as you add a new app in Pushwoosh.
There was quite an extensive blog post made by Holly Schinsky on easy PhoneGap integration with Pushwoosh
http://devgirl.org/2012/12/04/easy-phonegap-push-notifications-with-pushwoosh/
It should be very helpful for all PhoneGap developers aiming to integrate push notifications into their apps.
I found a really easy solution without using a framework.
I simply added the following code to the very end of the method didFinishLaunchingWithOptions (Right before the return statement):
if (launchOptions != nil)
{
NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
NSLog(#"Launched from push notification: %#", dictionary);
[self addMessageFromRemoteNotification:dictionary updateUI:NO];
}
}
Also, I added this new method to my AppDelegate.m which gets the payload from the push message:
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
NSLog(#"Received notification: %#", userInfo);
[self addMessageFromRemoteNotification:userInfo updateUI:YES];
}
(The NSLog calls above will show you what's inside the push message)
As a last step, I added this listener to do what ever I want with the payload:
- (void)addMessageFromRemoteNotification:(NSDictionary*)userInfo updateUI:(BOOL)updateUI
{
// do what ever you want with userInfo
}
If you want to do an additional JavaScript call with this info, I recommend using:
[self.viewController.webView stringByEvaluatingJavaScriptFromString:#"callSomeJSFunction()"];
Of course you can also pass arguments as strings into that JS function if you want.

Categories

Resources