首页 文章

iOS 10用户通知不允许每隔一段时间重复通知

提问于
浏览
0

http://www.openradar.me/26855019

使用新的iOS 10用户通知框架,人们无法再在每分钟或每小时重复的特定日期或时间安排通知 .

如何在用户通知框架中执行此操作?

2 回答

  • 0

    我找到了这个:

    https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SchedulingandHandlingLocalNotifications.html#//apple_ref/doc/uid/TP40008194-CH5-SW1

    您可以尝试为UNNotificationResponse定义类别,然后处理响应取决于类别类型 .

    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        if response.notification.request.content.categoryIdentifier == "TIMER_EXPIRED" {
            // Handle the actions for the expired timer.
            if response.actionIdentifier == "SNOOZE_ACTION" {
                // Invalidate the old timer and create a new one. . .
            }
            else if response.actionIdentifier == "STOP_ACTION" {
                // Invalidate the timer. . .
            }
        }
    
        // Else handle actions for other notification types. . .
    }
    
  • 0

    您可以根据时间,日历或位置触发通知 . 触发器可以重复:

    let date = Date(timeIntervalSinceNow: 60)
    let triggerMinute = Calendar.current.dateComponents([.minute,.second], from: date)
    let trigger = UNCalendarNotificationTrigger(dateMatching: triggerMinute, repeats: true)
    

    此代码尝试安排通知,使得日期的分钟和秒组件匹配,您可以按照您想要的方式对其进行配置 .

相关问题