【发布时间】:2016-06-05 14:41:23
【问题描述】:
我正在尝试让 iPhone 在通知中心内连续振动多次。 在对此进行研究时,我发现有几篇帖子说 Apple 只允许触发一个警报,因此每个警报只有一次振动。
我最近看到我的手机上有一个 WhatsApp 电话打进来,事情变得很疯狂。我尝试实现相同的行为。 一种可能的解决方案是一遍又一遍地删除和创建通知,但我很确定 Apple 会拒绝这种行为。
这可能是这样的:
var interval = 10
var i = 0
while(i < interval) {
sendNotification(message)
sleep(1)
UIApplication.sharedApplication().cancelAllLocalNotifications()
i += 1
}
sendNotification(message)
func sendNotification(text: String) {
let notification = UILocalNotification()
notification.alertBody = "This is a test"
notification.alertAction = "Stop Alarm"
notification.soundName = UILocalNotificationDefaultSoundName
notification.category = "ALERT"
UIApplication.sharedApplication().scheduleLocalNotification(notification)
那么,实现这一目标并遵守 Apple 准则的最佳方法是什么?
【问题讨论】:
-
您的应用是否接听电话?来电提醒与本地通知不同。
-
它更像是一个闹钟。
标签: ios iphone swift uilocalnotification