2016-05-23 4 views
-1

のは、こののStringArrayはすでにlocalNotificationに予定されている日付の文字列を持っているとしましょう、それらの文字列を取得する方法は、日付に変換して、特定の予定日にNSDateFormatter `ためNSDateに変換された後に文字列の配列から取得したlocalNotificationをキャンセルするにはどうすればよいですか?

var arr = ["2016-08-27 19:29:50 +0000","2016-09-20 17:19:50 +0000","2016-07-27 10:20:30 +0000"]** 

func locaNotification(num:Int) 

{ 

    let notification = UILocalNotification() 
    let notifTime = NSDate(notificationTime[num]) 
    UIApplication.sharedApplication().cancelLocalNotification(notification) 

} 
+0

ルックを削除し、そこにあります'NSDate'を' NSString'または 'NSString'に' NSDate'に変換します。 – Larme

答えて

1
let arrLocalNotif = UIApplication.sharedApplication().scheduledLocalNotifications 
for (let localN in arrLocalNotif) { 
    let notificationFireDate = localN.fireDate; 
    //convert string array value to date object and Compair this bothdate 
    if(compair true) { 
     UIApplication.sharedApplication().cancelLocalNotification(notification) 
      break 
    } 
} 
+0

スウィフトでお願いしますか? –

+0

ちょうどそれをスウィフトで書いた、それは働いた=)多くのありがとう –

+0

私は1つの最後の問題がある! 私は出力で取得if文で両方の日付を比較します状態を意味する 2016年5月23日午前13時55分○○秒0000 2016年5月23日13時53分38秒0000 秒で常に違いがあるので、決して真実ではありません!あなたは秒を比較無視する方法を知っていますか? –

関連する問題