如何在数据从 API 更改时发送推送通知
How to send push notification when data changes from API
我目前正在 Swift 中创建一个 iOS 应用程序,它从第三方 API 获取数据,然后将其显示在屏幕上。
其中一项功能包括启用推送通知,以便用户在 API 数据发生变化时收到推送通知。
但是,我正在努力弄清楚如何实现它的推送通知方面,以便我可以持续监控 API 数据,然后在数据发生变化时发送推送通知.
有人可以为我指明正确的方向吗?我以前使用 Firebase 来实现推送通知,但推送是由用户操作触发的。我想知道是否有类似的东西可以在 Firebase 中使用,或者是否有任何其他建议?
谢谢!
您也许可以使用云功能。如果您正在监控数据客户端,您或许可以调用云功能来发送推送通知。
或者您可能想查看本地通知。我不确定你到底想完成什么,所以很难说,但就方向而言,我建议你查看 cloud functions and local notifications 看看是否有任何一个能解决你的需求。
编辑:
既然我更了解您要查找的内容,我会查看这篇文章 here。它将解释后台应用程序刷新。这是文章的节选。
When the system calls your app delegate’s application(_:performFetchWithCompletionHandler:) method, configure a URLSession object to download any new data. The system waits until network and power conditions are good, so you should be able to retrieve adequate amounts of data quickly. When you finish updating your app, call the completion handler and provide an accurate result of your outcome, which can include saying that no new data was available.
所以在 application(_:performFetchWithCompletionHandler:) 方法中你会想要:
- 下载新数据
- 将它与旧数据进行比较,看看是否有变化
- 然后我可能只向用户显示本地通知。
我认为这将是您当前架构的最简单方法,而且无需编写任何服务器端代码。
我目前正在 Swift 中创建一个 iOS 应用程序,它从第三方 API 获取数据,然后将其显示在屏幕上。
其中一项功能包括启用推送通知,以便用户在 API 数据发生变化时收到推送通知。
但是,我正在努力弄清楚如何实现它的推送通知方面,以便我可以持续监控 API 数据,然后在数据发生变化时发送推送通知.
有人可以为我指明正确的方向吗?我以前使用 Firebase 来实现推送通知,但推送是由用户操作触发的。我想知道是否有类似的东西可以在 Firebase 中使用,或者是否有任何其他建议?
谢谢!
您也许可以使用云功能。如果您正在监控数据客户端,您或许可以调用云功能来发送推送通知。
或者您可能想查看本地通知。我不确定你到底想完成什么,所以很难说,但就方向而言,我建议你查看 cloud functions and local notifications 看看是否有任何一个能解决你的需求。
编辑:
既然我更了解您要查找的内容,我会查看这篇文章 here。它将解释后台应用程序刷新。这是文章的节选。
When the system calls your app delegate’s application(_:performFetchWithCompletionHandler:) method, configure a URLSession object to download any new data. The system waits until network and power conditions are good, so you should be able to retrieve adequate amounts of data quickly. When you finish updating your app, call the completion handler and provide an accurate result of your outcome, which can include saying that no new data was available.
所以在 application(_:performFetchWithCompletionHandler:) 方法中你会想要:
- 下载新数据
- 将它与旧数据进行比较,看看是否有变化
- 然后我可能只向用户显示本地通知。
我认为这将是您当前架构的最简单方法,而且无需编写任何服务器端代码。