小编Vas*_*kov的帖子

立即触发重复本地通知——如何推迟?

我的目标是设置一个将在未来 N 秒内第一次发生的通知,然后每 N 秒重复一次。

但是,创建重复通知似乎会UNUserNotificationCenterDelegate立即触发。

应用程序委托:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let center = UNUserNotificationCenter.current()
    center.delegate = self
    return true
}

func startRequest() {
    let content = UNMutableNotificationContent()
    content.body = bodyText
    content.categoryIdentifier = categoryIdentifier
    content.sound = UNNotificationSound.default()

    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)
    trigger.nextTriggerDate()
    let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)

    let center = UNUserNotificationCenter.current()
    center.add(request)
}

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) …
Run Code Online (Sandbox Code Playgroud)

notifications ios swift ios10

5
推荐指数
1
解决办法
1082
查看次数

标签 统计

ios ×1

ios10 ×1

notifications ×1

swift ×1