0

私の目標は、毎日繰り返されるリマインダー通知を設定することです。次のコードは、コードでの設定にもかかわらず、通知を一度だけ正常に表示しますが、繰り返しませんrepeat: true

通知コード全体は以下のとおりです。

    let notificationID = "daily_sleep_alarm"
    let title = "Rest your weary eyes"
    let body = "It's bedtime. The comfort of your blanket beckons you."

    UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [notificationID])
    
    let center = UNUserNotificationCenter.current()
    let content = UNMutableNotificationContent()
    content.title = title
    content.body = body
    content.categoryIdentifier = "daily_sleep_alarm"
    content.userInfo = ["customData": "fizzbuzz"]
    content.sound = nil

    var dateComponents = DateComponents()
    dateComponents.hour = hourSelected
    dateComponents.minute = minuteSelected
    let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
    let request = UNNotificationRequest(identifier: notificationID, content: content, trigger: trigger)
    center.add(request)

前述のように、このコードは 1 回で通知を正常に表示しません。この特定の で保留中の通知をクリアするコードは他にありませんnotificationID

アプリの起動時に、保留中の通知が で利用可能かどうかも確認しますがcenter.getPendingNotificationRequests、常になしと表示されます。

毎日の繰り返し通知を正しく設定するために何をする必要があるかについての洞察は大歓迎です。

4

1 に答える 1