gpt4 book ai didi

ios - 在照片访问请求回调中显示 View Controller 会抛出异常

转载 作者:行者123 更新时间:2023-11-28 11:14:09 27 4
gpt4 key购买 nike

我正在使用以下代码在我的应用程序启动时请求访问用户照片库。

@IBAction func requestPhotoLibraryAccess(sender: UIButton) {
PHPhotoLibrary .requestAuthorization { (status) -> Void in
if (status == PHAuthorizationStatus.Authorized) {
self.showViewController(HomeViewController(), sender: self);
}
}
}

我不明白的是,当我打电话

self.showViewController(HomeViewController(), sender: self); 

它抛出

2015-10-04 20:21:13.520 Bokeh[11284:1352415] 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.
Stack:(
0 CoreFoundation 0x000000010b48ef65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010d249deb objc_exception_throw + 48
2 CoreFoundation 0x000000010b48ee9d +[NSException raise:format:] + 205
3 Foundation 0x000000010b9ff3b5 _AssertAutolayoutOnMainThreadOnly + 79
4 Foundation 0x000000010b8601be -[NSISEngine withBehaviors:performModifications:] + 31
5 UIKit 0x000000010c653637 -[UIView(AdditionalLayoutSupport) _withAutomaticEngineOptimizationDisabledIfEngineExists:] + 58
6 UIKit 0x000000010c653fb9 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:forSecondPass:] + 154
7 UIKit 0x000000010c653c29 -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:forSecondPass:] + 309
8 UIKit 0x000000010c653fe5 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:forSecondPass:] + 198
9 UIKit 0x000000010c653c29 -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:forSecondPass:] + 309
10 UIKit 0x000000010c653fe5 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:forSecondPass:] + 198
11 UIKit 0x000000010c65461d __60-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]_block_invoke + 98
12 UIKit 0x000000010c653640 -[UIView(AdditionalLayoutSupport) _withAutomaticEngineOptimizationDisabledIfEngineExists:] + 67
13 UIKit 0x000000010c65417a -[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded] + 254
14 UIKit 0x000000010c654e8f -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeeded] + 272
15 UIKit 0x000000010be7360c -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 159
16 UIKit 0x000000010be83143 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 749
17 QuartzCore 0x000000011267a36a -[CALayer layoutSublayers] + 146
18 QuartzCore 0x000000011266ebd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
19 QuartzCore 0x000000011266ea4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
20 QuartzCore 0x00000001126631d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
21 QuartzCore 0x00000001126909f0 _ZN2CA11Transaction6commitEv + 508
22 QuartzCore 0x0000000112690cd4 _ZN2CA11Transaction14release_threadEPv + 224
23 libsystem_pthread.dylib 0x000000010e09939c _pthread_tsd_cleanup + 470
24 libsystem_pthread.dylib 0x000000010e098f78 _pthread_exit + 117
25 libsystem_pthread.dylib 0x000000010e097596 pthread_attr_getschedpolicy + 0
26 libsystem_pthread.dylib 0x000000010e095375 start_wqthread + 13
)

如果我将调用从回调中移出,它就可以正常工作。

Apple 文档没有说明它在后台线程上运行,尽管我认为这就是回调的全部意义。

This method always returns immediately. If the user has previously granted or denied photo library access permission, it executes the handler block when called; otherwise, it displays an alert and executes the block only after the user has responded to the alert.

我是否必须将导航编码回 UI 线程?

最佳答案

尝试

dispatch_async(dispatch_get_main_queue(),{

self.showViewController(HomeViewController(), sender: self);

})

代替

self.showViewController(HomeViewController(), sender: self);

关于ios - 在照片访问请求回调中显示 View Controller 会抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32940837/

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