在特定时间内,每天以每小时为间隔运行本地通知。

问题描述 投票:1回答:1

我怎样才能让我的应用程序能够每天以自定义的时间间隔发射本地通知,但只在分配的时间内发射,例如:从晚上10:00到20:00?

现在我只实现了自定义间隔的重复通知。

    func beginNotifications(_ config: UserConfig) {

    let interval = config.notificationInterval

    let center =  UNUserNotificationCenter.current()
    center.removeAllPendingNotificationRequests()

    let content = UNMutableNotificationContent()
    content.title = "Content title"
    content.subtitle = "Content body"
    content.sound = UNNotificationSound.default

    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: interval, repeats: true)

    let request = UNNotificationRequest(identifier: "notification", content: content, trigger: trigger)

    center.add(request)

}

到目前为止,我只想到了一个解决方案--使用Timer制作两个独立的方法,每天启动和停止通知功能,并为应用程序启用后台模式。

ios swift uilocalnotification localnotification
1个回答
0
投票

我想到的第一个解决方案是,如果调度本地推送通知N次(你想要多少次)。你只需要做 identifier 当然是独一无二的。

enter image description here


到目前为止,我只想出了一个解决方案--用Timer做两个独立的方法,每天启动和停止通知功能,并启用应用的后台模式。

这并不推荐 imo,如果你推崇这个,可能需要和苹果审核团队交涉。

© www.soinside.com 2019 - 2024. All rights reserved.