gpt4 book ai didi

ios - 更改照片设置后应用程序崩溃

转载 作者:可可西里 更新时间:2023-11-01 01:37:59 25 4
gpt4 key购买 nike

我有一个应用程序需要访问您设备上的照片。我检查设备状态,如果他们拒绝访问,我会触发一个模式,警告他们他们没有提供必要的访问权限,然后让他们选择进入他们的设置并更正选择。

发生这种情况时,我的应用程序崩溃并出现以下错误:

This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.

这是我触发重定向的代码。有什么想法可能导致这种情况或关于我应该如何做得更好的建议吗?

let title = "You didn't allow us to view your photos!"
let message = "Without access, we cannot help you add photos from your device."
let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)

alertController.addAction(UIAlertAction(title: "I know!", style: UIAlertActionStyle.Cancel, handler: nil))
alertController.addAction(UIAlertAction(title: "Settings (Required)", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction) -> Void in

let settingsURL = NSURL(string: UIApplicationOpenSettingsURLString)
UIApplication.sharedApplication().openURL(settingsURL!)
}))

self.presentViewController(alertController, animated: true, completion: nil)

此代码是在我从以下位置调用的方法中调用的:

PHPhotoLibrary.requestAuthorization({ (status: PHAuthorizationStatus) -> Void in
if(status == .Authorized){
self.getPhonePhotos()
}else{
self.showDeniedPhotosPopup()
}
})

提前致谢。

更新

我刚刚意识到我之前没有意识到的事情。如果我在设置中激活“照片”开关,代码只会崩溃。导航本身不会导致应用程序崩溃,它会在应用程序仍在运行时更改照片设置配置。为了验证我的理论,我从未触发弹出窗口,只是进入设置,激活照片开关,应用程序崩溃了。所以崩溃肯定是由于照片设置的变化引起的。

最佳答案

从错误来看,您似乎是在不是主线程的线程上呈现 View Controller ,导致在后台线程上的新 View Controller 上实现 UI 内容(自动布局等)。

尝试将您的 View Controller 表示代码封装在主队列中。像这样:

weak var aBlockSelf = self

dispatch_async(dispatch_get_main_queue(), {
aBlockSelf.presentViewController(alertController, animated: true, completion: nil)
})

如果它仍然崩溃,分析您的应用程序以找出确切的罪魁祸首。

关于ios - 更改照片设置后应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33459198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com