0
我想每隔一小時發送一次本地通知(僅限一天)使用不同的消息。還想在新的一個來臨時關閉先前的通知。iOS不同消息的本地通知
我使用此代碼但第二次通知與第一次使用相同的文本! 並不會關閉上一個...
UIApplication.sharedApplication().cancelAllLocalNotifications()
var Text = "!!!!!!!!!"
let Texts = [
"11111111111",
"22222222222",
"33333333333",
"44444444444",
"55555555555"
]
Text = Texts[Int(arc4random_uniform(UInt32(Texts.count)))]
let localNotification:UILocalNotification = UILocalNotification()
localNotification.alertAction = "Testing notifications on iOS8"
localNotification.alertBody = Text
localNotification.fireDate = NSDate(timeIntervalSinceNow: 1)
localNotification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
let localNotification2:UILocalNotification = UILocalNotification()
localNotification2.alertAction = "Testing notifications on iOS8"
localNotification2.alertBody = Text
localNotification2.fireDate = NSDate(timeIntervalSinceNow: 5)
localNotification2.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(localNotification2)