2016-05-26 3 views
1
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を返します!なぜ私はlocalNotificationで文字列の配列をアンラップするとnilを返しますか?

var arr = UIApplication.sharedApplication().scheduledLocalNotifications 
    for localN:UILocalNotification in arr! 
    { 
     var notificationFireDate:NSDate = localN.fireDate! 
     if notificationFireDate == newDate 
     { 
      UIApplication.sharedApplication().cancelLocalNotification(localN) 
     } 
    } 
} 

答えて

0

あなたの問題があることである:私はあなたの文字列と思い、 "YYYY-MM-DD HH MMは" あなたがこのウェブサイトにhttp://nsdateformatter.com/

を見ることができる適切ではない「2016年5月26日夜04時27分17秒+0000 "を" 2016-05-26T16:27:17 + 0000 "にする必要があります。フォーマットは" yyyy-MM-dd'T'HH:mm:ssZ "にする必要があります。

+0

ありがとうございました^ _ ^ –

0

あなたの日付フォーマッタで指定している日付形式は間違っています。あなたのnotificationTime配列の日付と一致しません。 日付形式として、yyyy-MM-dd HH:mm:ssZの形式で試すことができます。

関連する問題