Friday, March 10, 2017

OneSignal push notification with PHP

I'm using onesignal first time. I have already spent too much time on R&D. But output is almost zero. So here I go with my requirements.

  • I have a website. iOS app of the site and Android app too. Just like whatsapp or facebook.
  • When user logged in any of the above, user should get webpush notification or iOS notification, based on logged in device.
  • If user is logged in website as well as iOS app at a time, user should get notification on both.
  • If user gets logged out from iOS, user should not get notification in iOS device till he login again.
  • If another user login in to same iOS app, he should not get notifications of last logged in user. He should get only notifications related to him.
  • Same for website too.

I have successfully developed onesignal demo. But it is user independent. If I trigger notification, all the device gets notification. So here are my questions.

  • I have worked on GCM (I'm from PHP background). So as per my knowledge, push notification works on device id. So should I store multiple device id for a single user in my mysql database (for chrome, iOS, android etc)?
  • How will I get that device id? Remember, if user is not logged in, I don't want to send notification.
  • How to store it in my Database? I will pass that device id to my server by calling API and my server will store it in database. But when I should send? Because If user is not logged in, then how can I come to know that for which user I have to save device id?
  • How to check if user is changed on device or is same or is logged out?

If anyone can show me basic example, it will be appreciated. I'm from PHP side. It will be good for me if I get answer from PHP developer's view. I have already asked this question on stackoverflow. But answer was from Android view. But I think he doesn't know that on server side, we have to manage all the devices. So I haven't get much more from that answer.



via Akshay Vaghasiya

Advertisement