我的目标是在应用程序再次变为活动状态 / 进入前台时检查
该功能可以立即触发,但
UNUserNotificationCenter
的授权状态,并根据收到的信息打开或关闭一个UISwitch
。该功能可以立即触发,但
UISwitch
需要3-5秒才能更新。有没有更好的方法来更新它?override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(checkNotificationSettings), name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
}
func checkNotificationSettings() {
self.center.getNotificationSettings { (settings) in
switch settings.authorizationStatus {
case .authorized:
self.notificationSwitch.isOn = true
case .notDetermined, .denied:
self.notificationSwitch.isOn = false
}
}
}