的USERINFO对象符合要求使用夫特-2.2,为UILocalNotification
我想传递一个“结构”或“类对象”到UILocalNotification的用户信息。 (请参阅下面的代码图)。
你能告诉我如何改变这个结构以符合UserInfo的要求吗?
我读一些有关
一)的UserInfo不能是一个结构(但我也试图与一类 - 它没有工作,要么)
二)“的plist型”整合 - >但我该怎么做?
c)“NSCoder”和“NSObject”符合 - >但我该怎么做?
该错误消息我得到运行下面的代码是:
“无法序列USERINFO”
感谢您有这方面的帮助。
struct MeetingData {
let title: String
let uuid: String
let startDate: NSDate
let endDate: NSDate
}
let notification = UILocalNotification()
notification.category = "some_category"
notification.alertLaunchImage = "Logo"
notification.fireDate = NSDate(timeIntervalSinceNow: 10)
notification.alertBody = "Data-Collection Request!"
// notification.alertAction = "I want to participate"
notification.soundName = UILocalNotificationDefaultSoundName
let myData = MeetingData(title: "myTitle",
uuid: "myUUID",
startDate: NSDate(),
endDate: NSDate(timeIntervalSinceNow: 10))
// that's where everything crashes !!!!!!!!!!!!!!
notification.userInfo = ["myKey": myData] as [String: AnyObject]
这是一个很好的解决方案 - 非常感谢你! – iKK