![](/img/trans.png)
[英]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.