notificationTime = ["2016-05-26 16:27:17 +0000","2016-05-24 13:29:37 +0000"]
var num = 0
func locaNotification(num:Int)
{
let dateFormatter = NSDateFormatter()
dateFormatter.locale = NSLocale.currentLocale()
dateFormatter.dateStyle = NSDateFormatterStyle.FullStyle
var dateAsString = notificationTime[num]
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
var newDate = dateFormatter.dateFromString(dateAsString)!
它在此处解包时将返回nil,在上一行代码之后newDate = nil!
var arr = UIApplication.sharedApplication().scheduledLocalNotifications
for localN:UILocalNotification in arr!
{
var notificationFireDate:NSDate = localN.fireDate!
if notificationFireDate == newDate
{
UIApplication.sharedApplication().cancelLocalNotification(localN)
}
}
}
您的问题是“ yyyy-MM-dd HH:mm”不正确,您可以看到此网站http://nsdateformatter.com/
我认为您的字符串“ 2016-05-26 16:27:17 +0000”需要为“ 2016-05-26T16:27:17 + 0000”,而您的格式必须为“ yyyy-MM-dd'T' HH:mm:ssZ“,希望对您有所帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句