如何在UILocalNotifications中使用随机文本?

时间:2016-05-29 22:06:33

标签: arrays swift uilocalnotification arc4random

我正在尝试创建一个可以随机接收本地通知的应用。我使用了一些代码,但效果不佳。它只会来'" 006"或" 005",它不会改变。

我使用的代码是:

let myArray = ["000", "001", "002", "003", "004", "005", "006"]


let notification = UILocalNotification()
notification.alertBody = myArray[Int(arc4random_uniform(UInt32(myArray.count)))] // text that will be displayed in the notification
notification.fireDate = NSDate()  // right now (when notification will be fired)
notification.soundName = UILocalNotificationDefaultSoundName // play default sound
notification.repeatInterval = NSCalendarUnit.NSHourCalendarUnit // this line defines the interval at which the notification will be repeated

UIApplication.sharedApplication().scheduleLocalNotification(notification)
你可以告诉我哪里弄错了吗?感谢。

1 个答案:

答案 0 :(得分:0)

你在做什么是正确的。也许你还没有尝试过足够的代码并且有一长串极端值。

enter image description here