gpt4 book ai didi

UIViewController.presentViewController 中的 iOS 崩溃

转载 作者:搜寻专家 更新时间:2023-11-01 06:50:06 25 4
gpt4 key购买 nike

我有一个间歇性(很少发生)的崩溃,到目前为止只在 AppStore 的报告中发生过。由于崩溃日志有限,我无法理解这个问题。

我正在尝试显示 App Store 产品页面 View 。这是代码

The enclosing class includes the SKStoreProductViewControllerDelegate  and
the delegate is set to self.

@objc func adTap(sender: UITapGestureRecognizer? = nil) -> Void {
if adAppID.isEmpty {return}
let paramDict = [SKStoreProductParameterITunesItemIdentifier: adAppID]
storeProductViewController.loadProduct(withParameters: paramDict, completionBlock: { (status: Bool, error: Error?) -> Void in
if status {
self.storeProductViewController.view.frame.origin.y = 0
let eventParams = ["AppID": self.adAppID]
self.present(self.storeProductViewController, animated: true, completion: nil)
}
else {
if let error = error {
print("Error: \(error.localizedDescription)")
}
}})
}

错误在 self.present 触发:

#8  (null) in thunk for @escaping @callee_guaranteed (@unowned Bool, @guaranteed Error?) -> () ()

#7 0x100b68350 in closure #1 in ViewController.adTap(sender:)

#6 (null) in -[UIViewController presentViewController:animated:completion:] ()

#0 (null) in __exceptionPreprocess ()

转储实际的现金点文件显示 SIGABRT:

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0

Last Exception Backtrace:
0 CoreFoundation 0x1ad1db278 __exceptionPreprocess + 220 (NSException.m:199)
1 libobjc.A.dylib 0x1acf040a4 objc_exception_throw + 56 (objc-exception.mm:565)
2 UIKitCore 0x1b0bcbe0c -[UIViewController _presentViewController:withAnimationController:completion:] + 4880 (UIViewController.m:7185)
3 UIKitCore 0x1b0bce074 __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 104 (UIViewController.m:7671)
4 UIKitCore 0x1b0bce570 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 508 (UIViewController.m:7772)
5 UIKitCore 0x1b0bcdfc4 -[UIViewController _presentViewController:animated:completion:] + 196 (UIViewController.m:7678)
6 UIKitCore 0x1b0bce22c -[UIViewController presentViewController:animated:completion:] + 160 (UIViewController.m:7716)
7 MyAppName 0x100b68350 closure #1 in ViewController.adTap(sender:) + 1016 (ViewController.swift:991)
8 MyAppName 0x100b68580 thunk for @escaping @callee_guaranteed (@unowned Bool, @guaranteed Error?) -> () + 60 (<compiler-generated>:0)
9 StoreKit 0x1bba3c1e8 -[SKStoreProductViewController _loadDidFinishWithResult:error:] + 48 (SKStoreProductViewController.m:425)
10 StoreKit 0x1bba3e624 -[SKRemoteProductViewController loadDidFinishWithResult:error:] + 128 (SKRemoteProductViewController.m:61)

///////

我知道完成 block 是一个隐式转义 block ,但我看不出它如何不满足 block 规范(参数,如果这确实是问题所在)。同样,这是间歇性事件。从未在连接到 Xcode 的设备或我们的任何一台不受限制的设备上看到过它。最近在现场发生过,一次在运行iOS 13的iPhone 7上,一次在运行12.3.1的X上

/////

任何想法将不胜感激

最佳答案

让我把这个写成答案,因为我现在发现我的评论可能不清楚。 block

if status {
self.storeProductViewController.view.frame.origin.y = 0
let eventParams = ["AppID": self.adAppID]
self.present(self.storeProductViewController, animated: true, completion: nil)
}

访问一些 UI 元素,但它可能不在主线程上运行(因为它在回调中)。所以我首先怀疑的是,如果它恰好在主线程之外被调用,它就会崩溃。因此我会试试这个:

if status {
DispatchQueue.main.async {
self.storeProductViewController.view.frame.origin.y = 0
let eventParams = ["AppID": self.adAppID]
self.present(self.storeProductViewController, animated: true, completion: nil)
}
}

如果有帮助,也许可以考虑更好的 MVC 分离...

关于UIViewController.presentViewController 中的 iOS 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58084441/

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