所以我一直在努力解决这个神秘问题(至少对我而言)。它仅在App Store上发生。我尽力检查了BookingViewModel
代码,并确信那里应该没有崩溃,所以我做了一些清理工作,然后将新的版本上载到TestFlight,然后再次发生崩溃。 >
这是Fabric的Crashlytics崩溃日志的屏幕截图:
和一部分堆栈跟踪:
#0. Crashed: com.apple.main-thread
0 libswiftCore.dylib 0x103e70314 swift_unknownRelease + 24
1 libswiftCore.dylib 0x103e37b5c swift_arrayDestroy + 68
2 libswiftCore.dylib 0x103c308c0 (Missing)
3 libswiftCore.dylib 0x103e40f04 swift_unownedCheck + 88
4 appname 0x102940848 BookingViewModelBookingViewModelBooking first-element-marker empty-list String (BookingViewModel.swift:167)
最后,我的BookingViewModel
中的代码包含了崩溃日志中描述的第167行(我已经编辑了该问题的代码,我删除了一些行,但想法仍然存在,也使代码简短):
init(_ booking: Booking, withCompleteInfoCompletion completeInfo: @escaping BookingViewModelCompleteInfoCompletion) {
let createdDate = booking.createdAt ?? ""
let username = booking.username ?? ""
let firstName = booking.firstName ?? ""
let lastName = booking.lastName ?? ""
let age = booking.age ?? ""
let birthdate = booking.birthdate ?? ""
// Final values for completion
let userDetails = "\(firstName) \(lastName) \(age) / \(birthdate)".condensedWhitespace
// Booking Status and total amount
var bookingStatus: BookingStatus = .forProcessing
if let status = booking.status,
let statusId = status.id,
let newBookingStatus = BookingStatus(rawValue: statusId) {
bookingStatus = newBookingStatus
}
var totalAmount: Double = 0.00
if bookingStatus == .forPayment || bookingStatus == .paid || bookingStatus == .forConfirmation {
if let amounts = booking.amount {
for amount in amounts {
if let amountString = amount.amount,
let amountDouble = Double(amountString) {
totalAmount = totalAmount + amountDouble
}
}
}
}
self.subtotal = String(format: "%.2f", arguments: [totalAmount])
// Payment Method
var paymentType: PaymentType = .cod
if let paymentMethod = booking.paymentMethod,
let type = PaymentType(rawValue: paymentMethod) {
paymentType = type
}
// Initial Total
let initialTotal = "₱\(self.getTotalAmount(.paypal))"
completeInfo(
"₱\(self.subtotal)", // line 167
userDetails
)
}
问题是:对于从App Store或Testlfight下载的应用程序如何崩溃,而处于开发/调试模式(在Xcode中运行)却没有崩溃的问题,是否存在现有想法?
此外,是否可以在App Store上模拟项目的状态(例如,我已经读过某人的回答,因此可以将项目的代码签名更改为iOS Distribution
)?< / p>
谢谢!
答案 0 :(得分:2)
好的,如果外面有人被此类问题困扰,那么将导致奇怪崩溃的行放在主线程中会有所帮助!
我不确定为什么,也许我应该更多地检查代码。再说一次,我只需要像这样将崩溃行放入主线程即可:
DispatchQueue.main.async {
self.bookingViewModel = BookingViewModel(self.booking, withCompleteInfoCompletion: {
....
})
}
Larme的上述评论对我有很大帮助!