我遇到了间歇性(很少发生)崩溃,到目前为止,只有AppStore的报告才在野外发生。使用有限的崩溃日志,我无法解决该问题。
我正在尝试显示App Store产品页面视图。这是代码
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 ()
转储实际的Cashpoint文件会显示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)
///////
我理解完成块是一个隐式转义的块,但是我看不到它是如何不能满足块规范的(参数,如果确实是问题所在)。同样,这是一个间歇性事件。从未在连接到Xcode的设备上或在我们不受限制的设备之一上看到它。最近,它已在现场发生,一次是在运行iOS 13的iPhone 7上,一次是在运行12.3.1的X上
/////
任何想法将不胜感激
现在让我写这作为答案,因为我现在看到的评论可能不清楚。块
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分离...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句