2016-06-20 11 views
0

異なるメッセージを使用してローカル通知を毎時間(1日だけ)送信します。また、新しい通知が来たら、以前の通知を却下したい。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) 

答えて

0

を閉じていません、私は多分問題を解決

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) 

}

メソッドからテキストを取得するメソッドを作成してに警告テキストを変更:

localNotification2.alertBody = String(RandomText) 

しかし、これはいつも戻る:(機能)

関連する問題