当应用程序从后台状态变为前台时,我正在尝试刷新ui。 我将此代码添加到了我的viewcontroller
override func viewDidLoad() {
super.viewDidLoad()
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(checkNotificationAuthorization), name: UIApplication.willEnterForegroundNotification, object: nil)
}
@objc func checkNotificationAuthorization(completion: @escaping(Bool) -> Void){
var authorization = false
let current = UNUserNotificationCenter.current()
current.getNotificationSettings(completionHandler: { (settings) in
if settings.authorizationStatus == .denied {
authorization=false
} else if settings.authorizationStatus == .authorized {
authorization=true
}
completion(authorization)
})
}
每次使用Thread 1: EXC_BAD_ACCESS (code=1, address=0x8)
进入前台时,我的应用程序都会崩溃。在将completion
添加到checkNotificationAuthorization
之前,我尝试过它,并且效果很好。
有关该应用为何崩溃的任何想法?