我正在爲iOS 10的本地通知調度模塊,例如每週日或每週一重複本地通知..等等。比方說,我預定了這個日期的通知2016-12-27 10:53:22 +0000
,並使用UNCalendarNotificationTrigger
,重複值等於true,通知將在該日期觸發,並且不會在下週同時重複。重複用戶通知iOS 10的每個特定的一天
這可能是什麼原因?而且怎麼可能每週重複特定的一天,iOS的10
以下是創建本地通知代碼:
let content = UNMutableNotificationContent()
content.title = object.title
content.body = object.body
content.sound = UNNotificationSound.default()
let date = object.fireDate
let triggerDate = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second,], from: date as Date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate,
repeats: true)
// Swift
let identifier = object.id
let request = UNNotificationRequest(identifier: identifier,
content: content, trigger: trigger)
localNotification.add(request, withCompletionHandler: { (error) in
if error != nil {
// Something went wrong
print(error!)
}else {
print("Reminder \(object.id) has been added successfully at \(object.fireDate)")
}
})
更新:
我已經後還發現通知在該日期被解僱,並檢查是否沒有更多待處理通知存在或檢查它是否已被重新計劃。實際上重複次數等於真實,下週還沒有再次安排。
UNUserNotificationCenter.current().getPendingNotificationRequests(completionHandler: { (notficiations) in
for localNotification in notficiations {
print(localNotification)
}
})
,結果是:
<UNNotificationRequest: 0x174223ca0; identifier: A1, content: <UNNotificationContent: 0x1742e2980; title: My Title, subtitle: (null), body: My Body, categoryIdentifier: , launchImageName: , peopleIdentifiers: (
), threadIdentifier: , attachments: (
), badge: (null), sound: <UNNotificationSound: 0x1740b1820>, hasDefaultAction: YES, shouldAddToNotificationsList: YES, shouldAlwaysAlertWhileAppIsForeground: NO, shouldLockDevice: NO, shouldPauseMedia: NO, isSnoozeable: NO, fromSnooze: NO, darwinNotificationName: (null), darwinSnoozedNotificationName: (null), trigger: <UNCalendarNotificationTrigger: 0x174223cc0; dateComponents: <NSDateComponents: 0x17415e140>
Calendar Year: 2016
Month: 12
Day: 27
Hour: 14
Minute: 46
Second: 15, repeats: YES>>
我不知道,如果它實際上iOS中的錯誤或不。
一些解釋會顯着提高你的答案的質量 – mrun