我的应用程序在ios 10上完美运行,但在ios 11上它不会推送本地通知。我的代码中有错误吗?我已经搜索了很多但是找不到合适的解决方案这是ios 11中的一个错误吗? 的 的
的class AddReminderViewController: UIViewController , UNUserNotificationCenterDelegate{
// variables
var preControllerReference : ReminderViewController?
let center = UNUserNotificationCenter.current()
override func viewDidLoad() {
super.viewDidLoad()
center.delegate = self
center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
if error != nil {
print("Request authorization failed!")
} else {
print("Request authorization succeeded!")
}
}
setReminder()
// Do any additional setup after loading the view.
}
这是设置通知的功能
func setReminder(){
let content = UNMutableNotificationContent()
content.title = "Bee Productive"
content.body = "Buy some time"
content.sound = UNNotificationSound.default()
content.categoryIdentifier = "reminder-category"
let snoozAction = UNNotificationAction(identifier:"snooze", title: "Snooze", options:[])
let deleteAction = UNNotificationAction(identifier:"deleteAction", title: "Delete", options:[.destructive])
let category = UNNotificationCategory(identifier: "reminder-category", actions: [snoozAction,deleteAction], intentIdentifiers:[], options: [])
center.setNotificationCategories([category])
let date = self.reminderDatePicker.date
print(date)
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 3, repeats: false)
let identifier = "reminder-notification"
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger )
center.add(request) { (error) in
if let err = error {
print("something wrong \(err)")
}
}
}
的 任何想法都错了。提前致谢