gpt4 book ai didi

swift - iOS 间隔本地通知与不同的消息

转载 作者:行者123 更新时间:2023-11-30 13:19:16 24 4
gpt4 key购买 nike

我想每小时(仅一天)发送一 strip 有不同消息的本地通知。还想在新通知到来时关闭上一个通知。

我使用了这段代码,但第二个通知的文本与第一个通知相同!并且不会忽略上一个...

   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)

最佳答案

我创建了一个从方法中获取文本的方法也许可以解决问题

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)

但是总是返回:(函数)

关于swift - iOS 间隔本地通知与不同的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37924423/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com