每日排定的通知 [英] Daily scheduled notifications

查看:67
本文介绍了每日排定的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些指导,因此对于我的应用程序,我正在考虑使用本地通知在每天早上7点发送通知.

I need a bit of guidance, so for my application i'm looking at using local notifications to send a notification every morning at 7 o'clock.

我遇到的问题是如何使本地通知的内容主要是正文和附加图像动态化?由于每天都会对用户有所不同.

The issue i'm having is how can i make the content for the local notification dynamic mainly the body and the attached image? As it will vary for the user on a daily basis.

解决此问题的最佳方法是什么,因为您无法编辑以后的通知.

What would be the best way to go about this since you can't edit future notifications.

推荐答案

这里有一些关于通知的课程.首先,什么是通知?基本上,这是系统代表您发出的警报.其次,有两种通知:本地通知和远程通知.

Here's a little lesson about notifications. First, what is a notification? It's basically an alert presented on your behalf by the system. Second, there are two kinds of notification: local and remote.

让我们想象一下,一个旨在每天早晨7点向用户显示当前外部温度的通知的应用程序. (出于示例的目的,假设我们有一种学习此信息的方法.)

Let's imagine, then, an app that aims to present a notification to the user every morning at 7 AM saying what the current temperature is outside. (Assume for purposes of the example that we have a way of learning this information.)

片刻后就会发现,使用 local 通知无法做到这一点.我们无法在7 AM之前(或接近7 AM)知道当前温度,并且除非应用程序正在运行,否则我们无法安排通知.因此,我们需要非常好的运气才能让该应用程序在上午6:59运行,以便该应用程序能够正常工作.但是,只有当用户召唤该应用程序时,该应用程序才能运行,因此这种可能性很小.

A moment's thought will reveal that this cannot be done with local notifications. We cannot know the current temperature at 7 AM until 7 AM (or close to it) and we cannot schedule the notification unless the app is running. Therefore we would need the great good luck to have the app running at 6:59 AM in order for this app to work. But an app only runs when the user summons it, so that is extremely unlikely.

因此,只有通过 remote 通知才能执行此类任务.远程服务器始终在运行;因此,它可以获取温度并在上午7点"ping"用户的设备,系统将代表您显示通知.因此,您需要拥有这样的服务器才能编写想象中的应用程序.

Therefore a task of this kind is possible only with remote notifications. A remote server is always running; therefore it can get the temperature and "ping" the user's device at 7 AM, and the system will present the notification on your behalf. You would therefore need to possess such a server in order to write the imagined app.

(使用本地通知的另一种方法是:您预先安排一周的本地通知时间.然后,如果您有幸在通知发出前找到了正在运行的应用程序,则可以拆除所有计划的通知,并使用最新的预测再次执行此操作.但是,这当然不能像使用远程通知那样有效,并且如果用户不启动该应用程序,它将在一周后完全停止工作.坦率地说,这听起来很la脚.)

(An alternative using local notifications would be this: You schedule, say, a week's worth of local notification in advance. Then if you have the great good luck to find the app running before a notification is presented, you tear down all the scheduled notifications and do it again with a more up-to-date forecast. But of course this cannot possibly work as well as using remote notifications, and it will stop working entirely after a week if the user doesn't launch the app. That, to put it bluntly, sounds pretty lame.)

这篇关于每日排定的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆