【发布时间】:2016-02-07 14:27:33
【问题描述】:
我的事件日期输出正确,我的页面没有错误,但我的应用程序崩溃了,请帮忙?
我相信这可能与将我的 NSString 日期转换为 NSDate 有关
NSLog("This is the EventDate: \(eventdate)")
let date = eventdate as? NSString
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "YYYY-MM-dd HH:mm:ss"
var DateInFormat = dateFormatter.stringFromDate((date as? NSDate)!)
var notification:UILocalNotification = UILocalNotification()
notification.alertBody = "\(eventtitle) is about to start at the \(rsPubName)"
notification.category = "FIRST_CATEGORY"
notification.alertAction = "heyaaa"
notification.fireDate = date as? NSDate!
NSLog("This is the date: \(date)")
UIApplication.sharedApplication().scheduleLocalNotification(notification)
【问题讨论】:
-
发生了很多奇怪的可选事情。例如,
(date as? NSDate)!非常有趣。为什么不使用date as! NSDate?此外,字符串不能简单地转换为日期。他们必须通过NSDateFormatter的dateFromString:方法。
标签: swift nsdate uilocalnotification