Issues for sending push notification in ionic.io

464 Views Asked by At

I created a demo push notification by:

ionic start pushdemo

Add added the following code in app.js:

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {

    var push = new Ionic.Push({
      "debug": true
    });

    push.register(function(token) {
      console.log("Device token:",token.token);
      push.saveToken(token);
    });

Add I created push certificate and provisioning profile for iOS and also create an app in google for GCM.

Then I set the dev_push to false in .io-config.json.

I tested for Android by running the app in emulator:

ionic run android -lc

Doing this, I can get the device token. Then I'm able to send push notification by curl command:

curl -X POST -H "Authorization: Bearer xxxxeXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI3NjI4MzUyNi1mZjMxLTRhMGItODAxOC0xZmM2ZTY0ZTA3N2YifQ.xCSZk4vQwKajGQ4TOoWyN5GIPnA14jhYfDRMDrtxxxx" -H "Content-Type: application/json" -d '{    "tokens": ["DEV-67e379b0-0752-424c-9a73-0503ce0ad385"],    "profile": "pushdemo_dev",    "notification": {        "message": "Hello World!!!"    }}' "https://api.ionic.io/push/notifications"

I have no problem to receive the push notification when the app is running in foreground. But I'm not able to get the push notification when the app is in background.

The other issue is that the device token is always changed when app restart. Is this normal?

Another problem is I'm not able to get push notification when I push message through Dashboard in ionic.io.

Any idea? Thanks.

EDITED:

When I tested on ios device, I'm able to get the device token something like: 5137fcda 88b7e401 2dc7ac21 e4d80f96 d8702ee6 cd6e08ac 874a0b20 9a9882b0. But I can't get push notification when I used the above mentioned curl command. The returned value is:

{"data": {"created": "2016-06-10T09:17:07.031440+00:00", "config": {"profile": "pushdemo_dev", "notification": {"message": "Hello World ios!!!"}, "tokens": ["5137fcda88b7e4012dc7ac21e4d80f96d8702ee6cd6e08ac874a0b209a9882b0"]}, "status": "open", "uuid": "151f86f9-8b09-4e9c-9402-779544dbcbd1", "state": "enqueued", "app_id": "0dfdafd1"}, "meta": {"version": "2.0.0-beta.0", "request_id": "99e6891c-4fa5-40a9-a1ec-2fd283905c5f", "status": 201}}

EDIT 2:

Finally get it works in ios by using Postman to push. The format of device token returned is something like 5137fcda 88b7e401 2dc7ac21 e4d80f96 d8702ee6 cd6e08ac 874a0b20 9a9882b0. But when I post in Postman, I have to remove the space. However there is still a problem, I'm not able to receive push notification when I run the app in foreground. It only shows the push notificaiton when the app is running in background.

1

There are 1 best solutions below

0
On

my program also doent working on real devices but it isworking on browser it means my io is working fine and for you dont use dashboard instead use postman it is good