在不编码的情况下将自定义对象存储在 UILocalNotification 的 userInfo 中

Store custom objects in UILocalNotification's userInfo without encoding

我有一个名为 Person 的自定义 class,我想将其存储在 UILocalNotificationuserInfo (NSDictionary) 中。

有没有什么方法可以在不使用 -encodeWithCoder: 将其转换为 NSData object 的情况下保存它?

userInfo 字典有一些限制here

所以我认为,您需要序列化 ​​Person 对象才能将其存储在该位置。

一个简单的解决方法是给每个人一个唯一的 ID 并将该 ID 存储在 userInfo 中。 保存一个 person 的实例,并在需要获取 userInfo

时使用 id 获取它