[英]iOS 13.4 accessing MPMusicPlayerController.systemMusicPlayer crashes the app
[英]SwiftUI. App crashes on iPad with iOS 13.4-13.7 when long-pressed
這是我關於stackoverflow的第一個問題。 如果我格式化主題有誤,請糾正我。
嘗試在真正的 iPad 上使用長按(?觸覺?)時,應用程序崩潰。 它也可以在 Simulators iPad 上重現,並在 Magic Trackpad 上單擊 Force Touch。
從iOS 13.4到最后一個 iOS 13 的每個 iPad。 從iOS 13.4到最后一個 iOS 13 的每個模擬器 iPad。
我從未在 iPhone 上看到過這個錯誤。
我的測試設置:MacOS Catalina 10.15.6、 xCode 11.7 、Simulator iPad mini 2019 5-gen iOS 13.7、iPad 2018 6-gen iOS 13.7。
2020 年 10 月 26 日更新。 此外,我嘗試在 MacOS Catalina 10.15.7、iPad 2018 6 代 iOS 13.7 上使用 xCode 12.0.1 。 我重新測試了,看起來這個錯誤在iOS 13.4-13.7上仍然可用,但在iOS 14 上已經消失了。 我沒有找到適用於 iOS 13 的好決定。
TestCrashIPAD
)與 List、ForEach 和動態部分(下面的源代碼)一起使用。TestCrashIPAD
)。我在 AppDelegate 上崩潰了: Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
我調查了一下,發現:這個錯誤自 iOS 13.4 以來可重現。 在 iOS 13.4 中還有一個View Modifier onDrag (link) 。 可能是以某種方式連接的,因為在調用堆棧中我看到:
UIDragInteractionLongPressDriver
UIGestureRecognizer
動態部分數組可能有問題,因為我看到:
SwiftUI.Sections.rowIDs(forSectionAt: Swift.Int)
SwiftUI.ListCoreDataSource.rowIndex(at: Foundation.IndexPath)
如何解決這個問題? 在這種情況下如何解決而不崩潰? 請說任何想法。
請看一下源代碼:
import SwiftUI
struct TestCrashIPAD: View {
@State var sections = [TestSection]()
var body: some View {
List {
// predefined sections
Section(header: Text("Section predefined")) {
Text("1")
Text("2")
}
Section(header: Text("Section predefined")) {
ForEach(1..<7) {
Text("\($0)")
}
}
// dynamic content
ForEach(sections) { section in
Section(header: Text(section.title)) {
ForEach(section.rows) { row in
HStack {
Text(row.str)
Spacer()
}
}
}
}
}
.listStyle(GroupedListStyle())
.navigationBarTitle("iPad crash with long press")
.onAppear(perform: onAppearAction)
}
func onAppearAction() {
DispatchQueue.global().async {
// fetch some data from the server
sleep(3)
// show data in UI
DispatchQueue.main.async {
self.sections = [TestSection](TestSection.array)
}
}
}
}
struct TestSection: Identifiable {
let id = UUID()
let title: String
let rows: [TestRow]
static var array: [TestSection] {
var result = [TestSection]()
for idx in 0..<50 {
result.append(TestSection(title: "s\(idx)", rows: TestRow.array))
}
return result
}
}
struct TestRow: Identifiable {
let id = UUID()
let str: String
static var array: [TestRow] {
var result = [TestRow]()
for idx in 0..<Int.random(in: 3..<7) {
result.append(TestRow(str: "r\(idx)"))
}
return result
}
}
看起來答案是將.onLongPressGesture { }
添加到您崩潰的列表中(我從評論中得到了這個,但這解決了我的問題,所以似乎是一個答案。發布作為答案 bc 不是每個人都閱讀評論
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.