本地通知 UNTimeIntervalNotificationTrigger triggerWithTimeInterval 每1分钟触发一次 如何停止
Local notification UNTimeIntervalNotificationTrigger triggerWithTimeInterval fires every 1 minutes how to stops
我在我的应用程序中使用本地通知来提醒用户紧急消息。发生的情况是用户收到推送通知,然后创建本地通知并在 60 秒后触发,时间间隔为 60 秒。这很好用,紧急通知按预期每 60 秒触发一次。
The local notification star firing every one minute. But i want to
stop them. Can you suggest me how to handle this.
在 iOS 9 我们根本没有遇到这个问题,通知甚至会在一夜之间重复触发,所以我认为这可能与 iOS 10?[=12= 有关]
我用来创建通知的代码如下:
let content = UNMutableNotificationContent()
content.body = NSString.localizedUserNotificationString(forKey: notificationMessage, arguments: nil)
content.badge = 1
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)
let request = UNNotificationRequest.init(identifier: "", content: content, trigger: trigger)
center.add(request, withCompletionHandler: {(_ error: Error?) -> Void in
if error == nil {
print("add NotificationRequest succeeded!")
// trigger.timeInterval.
}
})
我找到了缺失的点
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey: "Elon said:", arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey: notificationMessage, arguments: nil)
content.sound = UNNotificationSound.default()
content.badge = UIApplication.shared.applicationIconBadgeNumber + 1 as NSNumber?
content.categoryIdentifier = "com.elonchan.localNotification"
// Deliver the notification in five seconds.
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 60.0, repeats: false)
let request = UNNotificationRequest.init(identifier: "FiveSecond", content: content, trigger: trigger)
// Schedule the notification.
center.add(request, withCompletionHandler: {(_ error: Error?) -> Void in
if error == nil {
print("add NotificationRequest succeeded!")
center.removePendingNotificationRequests(withIdentifiers: ["FiveSecond"])
}
})
我在我的应用程序中使用本地通知来提醒用户紧急消息。发生的情况是用户收到推送通知,然后创建本地通知并在 60 秒后触发,时间间隔为 60 秒。这很好用,紧急通知按预期每 60 秒触发一次。
The local notification star firing every one minute. But i want to stop them. Can you suggest me how to handle this.
在 iOS 9 我们根本没有遇到这个问题,通知甚至会在一夜之间重复触发,所以我认为这可能与 iOS 10?[=12= 有关]
我用来创建通知的代码如下:
let content = UNMutableNotificationContent()
content.body = NSString.localizedUserNotificationString(forKey: notificationMessage, arguments: nil)
content.badge = 1
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)
let request = UNNotificationRequest.init(identifier: "", content: content, trigger: trigger)
center.add(request, withCompletionHandler: {(_ error: Error?) -> Void in
if error == nil {
print("add NotificationRequest succeeded!")
// trigger.timeInterval.
}
})
我找到了缺失的点
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey: "Elon said:", arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey: notificationMessage, arguments: nil)
content.sound = UNNotificationSound.default()
content.badge = UIApplication.shared.applicationIconBadgeNumber + 1 as NSNumber?
content.categoryIdentifier = "com.elonchan.localNotification"
// Deliver the notification in five seconds.
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 60.0, repeats: false)
let request = UNNotificationRequest.init(identifier: "FiveSecond", content: content, trigger: trigger)
// Schedule the notification.
center.add(request, withCompletionHandler: {(_ error: Error?) -> Void in
if error == nil {
print("add NotificationRequest succeeded!")
center.removePendingNotificationRequests(withIdentifiers: ["FiveSecond"])
}
})