[英]Notifications in Ionic 2
I have gone through many posts. 我已经看了很多帖子。
Its bit confusing to understand that does ionic 2 app send local-notification even if my-app-is-killed-by-user or not ? 有点困惑的是,即使my-app被用户杀死了,ionic 2 app也会发送本地通知吗?
I have below scenario. 我有以下情况。
Assuming that app-is-killed-by-user
假设应用被用户杀死
Can we run the app in background (like after 24 hours check if some conditions are true by manipulating local/cloud storage) then send local notification ?
我们能否在后台运行该应用程序(例如24小时后通过操作本地/云存储来检查某些条件是否成立)然后发送本地通知?
I am new to ionic 2. So can anyone let me know that above scenario is possible ? 我是离子2的新手。那么有人可以让我知道上述情况是可能的吗?
If not possible then let me know that can we manipulate (get and analyse) local-storage via push notification server (assuming that app-is-killed-by-user) ? 如果无法实现,那么让我知道我们可以通过推送通知服务器(假设该应用被用户杀死)来操纵(获取和分析) 本地存储吗?
Both are possible. 两者都有可能。 I'll tell you how i would do them and not share code (it can be long), i'll give you the steps and you can figure it out.
我将告诉您我将如何做而不共享代码(可能会很长),我将为您提供步骤,您可以弄清楚。
For the first scenario you'll need LocalNotification plugin
, LocalStorage
, Platform
import from 'ionic-angular' and MomentJS
(not required, but highly recommended). 对于第一种情况,您需要从'ionic-angular'和
MomentJS
导入LocalNotification plugin
, LocalStorage
, Platform
(不是必需的,但强烈建议)。
app.components
. app.components
。 Platform
methods to verify and set the LocalNotification
, they're .pause
, .resume
and .ready
. Platform
方法来验证和设置LocalNotification
,它们是.pause
, .resume
和.ready
。 Moment().add(1, 'day').unix()
and use the result in the 'at' of your schedule. Moment().add(1, 'day').unix()
并在'at'中使用结果您的时间表。 this.storage.set('Daily', ReturnedID);
this.storage.set('Daily', ReturnedID);
,将此ID像this.storage.set('Daily', ReturnedID);
一样保存在您的localStorage中this.storage.set('Daily', ReturnedID);
The second scenario is a little bit harder and you'll need a back-end for this since you'll need to keep checking the time that user has gone off the app. 第二种情况要难一些,并且您需要一个后端,因为您需要不断检查用户退出应用程序的时间。 You'll need only
MomentJS
, the Platform
import, you push service plugin and a way to connect to your database (via Http or plugin, if it's a service like Firebase). 您只需要
MomentJS
, Platform
导入,推送服务插件以及一种连接到数据库的方式即可(通过Http或插件,如果它是Firebase之类的服务)。
Sorry i can't share some code, but if you need furter explanation or ideas just ask. 抱歉,我无法共享一些代码,但是如果您需要更多的解释或想法,请询问。 Hope this helps :D
希望这会有所帮助:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.