是否可以将 UILocalNotification 对象保存到 plist 或 sqlite 数据库或其他位置(例如 NSUserDefaults)?

发布于 2024-12-05 01:22:59 字数 615 浏览 0 评论 0原文

我想保存 UILocalNotifications 的对象,如下所示,最好是在我可以检索它的地方,并且能够保存多个 UILocalNotification 对象

    UILocalNotification *local=[[UILocalNotification alloc]init];
    [local setAlertBody:str];
    [local setFireDate:dat];
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"some_id_to_cancel" forKey:@"ID"];
    local.userInfo = infoDict;
    //local.hasAction=NO;
    //[[UIApplication sharedApplication] presentLocalNotificationNow:local];
    [[UIApplication sharedApplication] scheduleLocalNotification:local];
    [local release];

现在我想将本地对象保存在某个地方,例如 plist 或任何我可以检索它们的存储。

I want to save the objects of UILocalNotifications such as following, preferably somewhere from where I can retrieve it and could be able to save multiple UILocalNotification objects

    UILocalNotification *local=[[UILocalNotification alloc]init];
    [local setAlertBody:str];
    [local setFireDate:dat];
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"some_id_to_cancel" forKey:@"ID"];
    local.userInfo = infoDict;
    //local.hasAction=NO;
    //[[UIApplication sharedApplication] presentLocalNotificationNow:local];
    [[UIApplication sharedApplication] scheduleLocalNotification:local];
    [local release];

Now I want to save local object somewhere such as plist or any storages from where I could get retrieve them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难理解 2024-12-12 01:22:59

像这样的东西:

[NSKeyedArchiver archiveRootObject:local toFile:@"path_to_file_where_to_save"];

Something like this:

[NSKeyedArchiver archiveRootObject:local toFile:@"path_to_file_where_to_save"];
黑寡妇 2024-12-12 01:22:59

既然 UILocalNotification 符合 NSCoding 协议,那么,是的。

来自文档

NSCoding 协议声明了类必须实现的两个方法,以便可以对该类的实例进行编码和解码。此功能为归档(对象和其他结构存储在磁盘上)和分发(对象复制到不同的地址空间)提供了基础。

Since UILocalNotification conforms to the NSCoding protocol, then, yes.

From the documentation

The NSCoding protocol declares the two methods that a class must implement so that instances of that class can be encoded and decoded. This capability provides the basis for archiving (where objects and other structures are stored on disk) and distribution (where objects are copied to different address spaces).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文