2016-06-20 11 views
0

Ich mag eine lokale Benachrichtigung Jeder Stunde (nur für einen Tag) senden mit verschiedener Nachricht. Wollen Sie auch die vorherige Benachrichtigung ablehnen, wenn neue kommt.iOS Intervall Lokale Benachrichtigung mit unterschiedlichen Nachrichten

I Gebraucht Dieser Code But The seccond Mitteilung Kommt mit dem gleichen Text wie erste! und macht die vorherigen nicht Entlassen ...

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) 

Antwort

0

habe ich eine Methode den Text aus Methode Vielleicht löst das Problem

internal func RandomText(Text: String) -> (String){ 

var Text = "!!!!!!!!!" 
let Texts = [ 
    "11111111111", 
    "22222222222", 
    "33333333333", 
    "44444444444", 
    "55555555555" 
] 

Text = Texts[Int(arc4random_uniform(UInt32(Texts.count)))] 
return(Text) 

}

und den Alert-Text geändert zu erhalten, :

localNotification2.alertBody = String(RandomText) 

aber immer zurück: (Funktion)

Verwandte Themen