从应用程序内部触发推送通知 [英] Trigger a push notification from inside the app
问题描述
是否可以从应用本身内部触发推送通知?
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?
注意:缓存的文件将为JSON格式.
Note: the cached file will be in JSON format.
推荐答案
要使其成为可能,您将必须永久检查更新,这将消耗用户的电池并消耗网络资源容量,因此设置服务器来实现此任务是解决问题的方法.
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.
它看起来像这样:
- 将设备的推送令牌发送到服务器,并订阅对文件的更改.
- 更改远程文件时,在服务器上触发操作.
- 使用您在步骤1中获得的推送令牌将通知发送给那些订阅了文件的设备.
要了解有关推送通知如何工作的更多信息,请查看此出色的教程这里.
To learn more about how push notifications work, you can have a look onto this great tutorial here.
这篇关于从应用程序内部触发推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!