使用线程1崩溃:EXC_BAD_ACCESS(代码= 1,地址= 0x8)快速

时间:2019-12-18 22:47:19

标签: swift completion addobserver

当应用程序从后台状态变为前台时,我正在尝试刷新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之前,我尝试过它,并且效果很好。 有关该应用为何崩溃的任何想法?

0 个答案:

没有答案