如何在 UserDefault 中存储推送通知警报消息? [英] How can I store Push Notification alert message in UserDefault?

查看:22
本文介绍了如何在 UserDefault 中存储推送通知警报消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建一个应用程序,我可以接收推送通知并保存在客户端设备中以限制 25 个通知.如果应用程序正在运行并且可能未运行.如何存储 PushNotification 警报消息?.如果运行该时间的应用程序到达通知警报消息存储在 UserDefault 中,但当应用程序处于后台或非活动状态时,该时间未将通知警报消息存储在 UserDefault 中.我想知道我是否需要使用 UserDefault 或 CoreData 在客户端应用程序中存储推送通知消息?如果不是,我应该使用什么?我真的需要一只手来接我.

I want to build an app that I can receive push notification and save inside client device for limit 25 Notification. If application running and may not running. How can I stored PushNotification alert message?. If app running that time arrived Notification alert message stored in UserDefault but when app in background or Inactive state that time not stored Notification alert message in UserDefault. I want to know that I need to use UserDefault or CoreData to store the Push Notification message inside client app or not? If it is not, what should I use? I really need a hand to pick me up.

请帮忙.谢谢.

推荐答案

在我看来,您可以使用 NSUserDefaults 来存储用户相关信息.在您的情况下推送通知.然而,只是一个想法,您可以简单地将通知附加到本地存储或用户设备上的 txt 文件,并在用户访问时删除该元素.

In my opinion you can use NSUserDefaults to store user related information. Push Notifications in your case. However, just a thought, you can simple append the notifications to local storage or a txt file on user device and remove the element as user accesses it.

但这仅在用户使用应用程序时有效.如果您希望即使在应用程序不工作时也能正常工作,您需要创建一个后端并将这些数据存储在某种云数据库中.您可以从数据中提取记录,并在再次打开应用程序时再次推送到 NSUserDefaults 或本地 txt 文件.

But this will only work when user is using the app. In case you want to make this work even when the app is not working, you need to make a backend and store these data in some kind of cloud database. You can extract the records from data and push again to NSUserDefaults or local txt file when the app is turned on again.

这篇关于如何在 UserDefault 中存储推送通知警报消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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