Ionic - Push notification

Thank You So Much… I Got Device Token, Then Next Step Mention Please
The Exact Problem Is Android studio Is not up to date

I Got Device Token, But I send Notification Through Post Man, Status is created sucessfully. but In mobile not getting notification

Hi @ankushagg93,
I am getting error while implementing this in my existing app-

TypeScript error: app/app.ts(43,27): Error TS1138: Parameter declaration expected.
TypeScript error: app/app.ts(43,28): Error TS1109: Expression expected.
TypeScript error: app/app.ts(43,31): Error TS1128: Declaration or statement expected.
TypeScript error: app/app.ts(91,8): Error TS1128: Declaration or statement expected.
TypeScript error: app/app.ts(92,5): Error TS1128: Declaration or statement expected.
TypeScript error: app/app.ts(94,19): Error TS1005: ‘;’ expected.

I think there is some issue with app.js code
can you give me a link for this application like github if you have pushed it there.

We are using https://gcm-http.googleapis.com/gcm/send to send payload, you are using https://api.ionic.io/push/notifications. Try this url, else try using java code mentioned in article used for push notification from server side.

See https://forum.ionicframework.com/t/ionic-2-push-notification/53898/18?u=ankushagg93. Also, if you can show your app.ts code, it will help in debugging as it’s impossible to tell error in code without seeing code itself :grin:

I’ve created a git repo for push notification demo

https://github.com/aggarwalankush/ionic2-push-base

Also, server code to push notification

https://github.com/aggarwalankush/push-notification-server

2 Likes

thanks @ankushagg93,
I am new to ionic, I think you are using


to send a push message to devise!!!

can’t we do this same uisng thinrd party service as

I also don’t know how to use this because it seems java code.

Device token how i send to server in ionic v2
i got errors that code mention here , please Tell me to how i send device token to Server (Post method) Please attach the code
----------------------------------------Post Moethod is it Right or Wrong ? -----------------
In Constructor
http: Http;
data = “”;

user = {“YOUR_DEVICE_TOKEN”:""+data.registrationId};
console.log(JSON.stringify(user));

this.http.post(‘http://192.168.1.39:8081/controler/ionic2notification’, user)
.map(res => res.json())

         .subscribe( obj => {
          console.log(JSON.stringify(obj)) ,
          this.data = obj;
            alert(this.data.status)


         },

         error => {
           alert("network error")
          //console.log(JSON.stringify(error.json()));
          return false;
      })

There are many ways to write server code, I just gave a sample in Java. You just need device token and api key to push.

You don’t need to send token to server, in my code it’s a comment. When you will run you app, you will see device token in console, just note it down and use for push notification. If you want you can use my AndroidPush.java code to push. Also, if you just follow readme file in my repo without any code changes, push notifications will work and over attached screenshots also

my server application is a web application if i want to send a push notification to the mobile app should my web application has to register with gcm or not. As the given url is a http protocol I directly sent a request to send push notification it is giving 200 as status but the mobile app is not receiving the notification. So please solve this.

Hi,

I got the basic push notification working. But when the app is closed, i don’t get the notifications on my android device. Any idea how to solve that?

Thanks
Kousik

Hi Ankush,

I am using Ionic 2 push notification with angular.

I could generate the device token, but I can’t figure out how to handle notifications. The code provided on the ionic site doesn’t seem to be working.

Could you please tell me how did you handle notifications?

See if this is useful Ionic Push Notification - Android and iOS working

Thank you for your prompt response.

Since I am using angular, I don’t know where do I import the Push class.

Hello guys

I am just start to play around ionic push once i send push from ionic Dashboard i receive that push in app but once i try to access it through Rest API using angular 2/ nodejs then i got this output

{"meta": {"version": "2.0.0-beta.0", "request_id": "05e88386-f405-4acf-cadf-33063df787c2", "status": 201}, "data": {"status": "open", "state": "enqueued", "config": {"profile": "demo", "notification": {"message": "Hello World!"}, "tokens": ["djObsfRcV_Y:APA91bEj_8LNlUMGVou9CzfEwTvwfain3vC9ckGMUT98T2g8t0G__eu_wpoZWbzSSFssXK4v2mOWtxa6csU8HjvSBQhY1eqoYJZpxXsKjw6EZDeV5bdRP2NHCYf2sCrHhPCifg_V39Qo"]}, "uuid": "2001a2a3-2095-4729-8c20-d03a62c6b785", "created": "2017-03-02T12:22:49.537210+00:00", "app_id": "053e90c2"}}

But i didn’t able to receive push on my app.

Can you please help me out what exactly the issue.

Thanks.

Can you please explain,How to run or use server code in ionic 2??
with sample

Running instructions are mentioned here https://github.com/aggarwalankush/push-notification-server#push-notification-server

i followed your tutorial from your blog tphangout and i am having an error saying “Error subscribing for Push notifications.”.
provide me solution please.

Could you please follow the instructions here - http://tphangout.com/ionic-2-push-notifications-with-firebase/