所以我一直在为这个神秘的问题(至少对我来说)发怒。它只发生在App上。我尽力检查了我的BookingViewModel代码,我确信不应该有崩溃,所以我做了一些清理,然后上传了一个新的构建到TestFlight,并再次发生崩溃。
下面是来自Fabric's 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行的代码在crashlog中被描述了(我已经为这个问题编辑了代码,我删除了一些行,但想法仍然存在,也是为了使代码简短):
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或Testlfight下载时,而不是在开发/调试模式(运行在Xcode中)时,应用程序如何会崩溃?
另外,在Also上模拟项目的状态是否可能(例如,我已经阅读了某人的答案,以便我可以将项目的代码签名更改为iOS Distribution)?
谢谢!
发布于 2018-07-12 03:39:41
好的,如果有人被这样的问题窃听,在主线程中放置导致怪异崩溃的线会有所帮助!
我不知道为什么,也许我应该更多地检查代码。因此,我只需要将崩溃线插入主线程,如下所示:
DispatchQueue.main.async {
self.bookingViewModel = BookingViewModel(self.booking, withCompleteInfoCompletion: {
....
})
}上面的评论对我有很大的帮助!
https://stackoverflow.com/questions/51283464
复制相似问题