Trigger a push notification from inside the app

China☆狼群 提交于 2020-01-24 00:28:08

问题


Is it possible to trigger a push notification from inside the app itself?

I need to build a function that compares a remote file to a cached file and if there is any new content on the remote file it updates the cache and triggers a push notification from the app itself.

I was wondering if this is possible? And if so how would I go about building it?

Note: the cached file will be in JSON format.


回答1:


To make this possible, you would have to permanently check for updates, which would drain the user's battery and consume networking capacity, so setting up a server to realise this task is the way to go here.

It would look somewhat like this:

  1. Send your device's push token to your server and subscribe to changes to the file.
  2. Trigger action on server, when remote file changes.
  3. Send notification to those devices that subscribed to the file using the push token you got in step 1.

To learn more about how push notifications work, you can have a look onto this great tutorial here.



来源:https://stackoverflow.com/questions/36707349/trigger-a-push-notification-from-inside-the-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!