如果从iOS设置禁用通知访问时已安排本地通知,则不会在iOS 13上激发本地通知
在我的应用程序中,我使用以下方法安排本地通知:如果从iOS设置禁用通知访问时已安排本地通知,则不会在iOS 13上激发本地通知,ios,swift,localnotification,unusernotificationcenter,Ios,Swift,Localnotification,Unusernotificationcenter,在我的应用程序中,我使用以下方法安排本地通知: func addNotificationRequest(fireDate: Date, identifier: String, sound: UNNotificationSound) { let notificationCenter = UNUserNotificationCenter.current() let content = UNMutableNotificationContent()
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上,我发现了一个可以通过以下步骤复制的bug:
静态函数showNotificationDisabledInfo(){
打印(“信息:通知权限被拒绝,需要在设置中重置!”)
showAlertMessage(标题为:“通知已禁用!”,
正文:“转到设置应用程序以重新启用通知。”,
类型:。信息)
}
很可能这就是它的工作原理。如果用户禁用了通知,为什么还要麻烦系统安排通知呢?您可能希望检查应用程序是否禁用了通知,并推迟通知计划?可能有一个变量,它会在每次应用程序进入前台时检查通知是否已启用,如果为true
,则会安排通知。当设备处于终止状态时,我们如何启动本地通知。我需要添加这个功能来制作视频通话提醒,比如whatsapp。