ios - UILocalNotification 我的警报每分钟触发一次 swift 2.0

标签 ios iphone swift uilocalnotification

我需要你的帮助。我为 localNotifications 编写代码。

func scheduleNotification() {
   // Schedule the notification
   let localNotification = UILocalNotification()
   localNotification.fireDate = dueDate
   localNotification.timeZone = NSTimeZone.defaultTimeZone()
   localNotification.alertBody = text
   localNotification.soundName = UILocalNotificationDefaultSoundName
        // at first start I write this line [1]
   // localNotification.repeatInterval = NSCalendarUnit.Second
   localNotification.repeatInterval = NSCalendarUnit.Weekday
   UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}

在这个区域 [1] 首先,我使用 NScalendarUnit.Second 编写该代码并启动我的应用程序。警报触发得很好,但它不会停止并且每分钟都会触发。之后,我从 iPhone 中删除我的应用程序,并粘贴带有工作日行的新代码行。我启动应用程序并添加新警报工作正常,但我在第一次启动时创建的第一个警报在触发第二个警报后每分钟都会触发。

最佳答案

您仍然需要取消旧的重复通知。

您可以使用 scheduledLocalNotification 检索当前计划通知的列表,然后您可以使用 cancelLocalNotification 取消它经过适当的过滤。

或者您可以使用cancelAllLocalNotifications如果您没有任何其他通知,请直接发送。

关于ios - UILocalNotification 我的警报每分钟触发一次 swift 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34571891/

相关文章:

ios - 断言失败 : (result == KERN_SUCCESS), 函数 +[XPCMachSendRight wrapSendRight:]

ios - 链接图标和社交网络

iphone - iPad 模拟器 (4.3) 崩溃并出现 dyld 错误

iphone - MFMailComposeViewController : Attaching Images from Photo Gallery

ios - 检查节点是否为 SKShapeNodes

ios - 从数组添加 `overlay` 修饰符 | swift 用户界面

ios - 呈现一个 View Controller ,关闭它并在 Swift 中呈现一个不同的 View Controller

ios - UITextView contentSize.height 比必要的大?

ios - 在 Storyboard 中更改标签栏项目的选定颜色

ios - 如何在iOS sdk中使用正则表达式