[英]iOS : Notification scheduled in past showing up on enabling from settings through “Allow Notifications”
[英]Local notification not fired on iOS 13 if it was scheduled when notifications access is disabled from iOS Settings
在我的應用程序中,我使用以下方法安排本地通知:
func addNotificationRequest(fireDate: Date, identifier: String, sound: UNNotificationSound)
{
let notificationCenter = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "Important"
content.body = notificationMessage
content.sound = sound
content.categoryIdentifier = "UserActions"
let calendar = Calendar(identifier: .gregorian)
let triggerDate = calendar.dateComponents([.hour, .minute, .second], from: fireDate)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate, repeats: true)
let notificationRequest = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
notificationCenter.add(notificationRequest) { error in
if let error = error
{
print(error.localizedDescription)
}
}
let myAction = UNNotificationAction(identifier: "MyActionID", title: "Open", options: [.foreground])
let category = UNNotificationCategory(identifier: "UserActions", actions: [myAction], intentIdentifiers: [], options: [])
notificationCenter.setNotificationCategories([category])
}
通知應該在給定的時間觸發,並且應該每天在同一時間重復。
在 iOS 13 上,我發現了一個可以通過以下步驟重現的錯誤:
也許有些人也發現了這個錯誤,並對如何修復有任何建議。 任何幫助表示贊賞。
星空是對的!
根據蘋果的文檔:
在嘗試從您的應用程序安排本地通知之前,請確保您的應用程序已獲得授權,因為用戶可以隨時更改您的應用程序的授權設置。 用戶還可以更改您的應用允許的交互類型,這可能會導致您更改配置通知的方式。
如果權限被禁用,您將不得不在安排通知時“靜默失敗”,或者通知用戶他們需要進入“設置”應用程序以重新啟用它們:
就我而言,我使用SwiftMessages做了類似的事情:
static func showNotificationDisabledInfo() {
print("INFO: Notification permissions denied, need to reset in Settings!")
showAlertMessage(withTitle: "Notifications are disabled!",
body: "Go to the Settings app to re-enable notifications.",
type: .info)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.