问题
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:
- Send your device's push token to your server and subscribe to changes to the file.
- Trigger action on server, when remote file changes.
- 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