Ionic1 Push Notification by using Ionic IO Services


#1

Hi Everyone,
I know there are plenty of references already available to implement push notification from scratch. It seems simple initially but i have got stuck in between and not able to decide where is is issue in my approach to implement push notification in ionic 1.

I have used below references for building my sample app

https://devdactic.com/ionic-push-notifications-guide/

  1. I have set my GCM Project and API Key on Google Cloud
  2. I have set my security profile using the same GCM API key in Ionic IO.

I have my app running in browser which have generated and displaying the device token.

Now i am trying to send Ionic Push messages from ionic io but all the messages are going in send state and none of them status is changing.

I have even tried to publish by using a sample node js script or by using PostMan pluggin but its failing with below error :

STATUS: 401
HEADERS: {“connection”:“close”,“server”:“nginx”,“date”:“Wed, 14 Sep 2016 03:36:5
5 GMT”,“content-type”:“application/json; charset=utf-8”,“content-length”:“196”,“
via”:“1.1 vegur, 1.1 vegur”,“access-control-allow-credentials”:“true”,“access-co
ntrol-allow-methods”:“HEAD,GET,POST,PATCH,PUT,DELETE,OPTIONS”,“access-control-al
low-headers”:“DNT,Authorization,X-CSRFToken,Keep-Alive,User-Agent,X-Requested-Wi
th,If-Modified-Since,Cache-Control,Content-Type”}
BODY: {“meta”: {“request_id”: “87cae260-72cb-4138-8737-0cb23e6d425e”, “status”:
401, “version”: “2.0.0-beta.0”}, “error”: {“type”: “Unauthorized”, “link”: null,
“message”: “JWT decode error occurred.”}}

Here is the node script :

var ionicPushServer = require(‘ionic-push-server’);

var credentials = {
IonicApplicationID : “48e8672d”, // app_id
IonicApplicationAPIsecret : “9e330522a91be8a2714a52371e4b94d13a4d9a074cab8b5e” // io
};

var notification = {
“tokens”:[“DEV-11f90c9f-7d07-414c-aa32-7640e4ebe1a3”],
“notification”:{
“alert”:“Hi from Ionic Push Service!”,
“android”:{
“badge”:1,
“sound”:“chime.aiff”,
“expiry”: 1423238641,
“priority”: 10,
“contentAvailable”: true,
“payload”:{
“key1”:“value”,
“key2”:“value”
}
}
}
};
ionicPushServer(credentials, notification);

I am not sure how do i trace whether the issue is

a. between Ionic Push and GCM
b. or From GCM to My application

I want to first verify the demo in my web browser to see if i am able to publish from Ionic Push > GCM > My application (or phone)

Need any help if there is a better way to test this flow. Sorry for asking the same steps again


#2

Hi All,
Able to resolve the issue. It was problem with the request parameter using Curl or PostMan.

Able to publish notification on my real device.

  1. Now the issue is the notification comes only when the app is open

  2. After changing the dev_push=false, my browser giving error as :

ionic.io.bundle.min.js:3 Uncaught TypeError: Cannot read property ‘init’ of undefined

I believe this error lot of people have experienced it. so searching now to resolve this issue

Thanks
Rohit Gupta


#3

What was the issue with request parameter. Can you provide screenshot of correct postman request?


#4

Here is my current postman setup. I am using “external_ids” as an identifier, so you probably want to change this to your needs.

HEADER

BODY


#5

Hi Edward,
I am trying to do a very simple push-
see below image


But it shows message as below -

Could you please suggest possible issues-


#6

Hm. Your settings seem to be correct. You might want to check the “Authorization”-Tab in Postman (next to Headers) if this is set to “No Auth”.

However, i think this has to do with your certificates, so maybe you want to consider going through the whole process one more round and follow these steps: http://docs.ionic.io/services/push/


#7

Hi Ed,
Thanks for the reply…
Auth type was set to No Auth so no worries from that point of view.
Anyways I have solved the issue by modifying the postman request, as request param were not getting recognized in ionic.io service until it was mentioned specifically in Headers tab…

Thanks for your time… I appreciate your efforts to help me.
Thanks
Basu


#8

Hi Basu,
I’ve same problem, Can you tell me how to fixed it in more detail ?

Thanks


#9

Hey Donc1991,

I resolved the issue by removing parameters(content-type and authorization) from the param section of postman and then added those parameter to the headers section and it worked.