[英]SwiftUI. App crashes on iPad with iOS 13.4-13.7 when long-pressed
It's my first question on stackoverflow.这是我关于stackoverflow的第一个问题。 Please correct me if I wrong with formatting topic.
如果我格式化主题有误,请纠正我。
I get crash of application when try use long press (?haptic touch?) on real iPad.尝试在真正的 iPad 上使用长按(?触觉?)时,应用程序崩溃。 Also it's reproducible on Simulators iPad with Force Touch click on Magic Trackpad.
它也可以在 Simulators iPad 上重现,并在 Magic Trackpad 上单击 Force Touch。
Every iPad since iOS 13.4 until the last iOS 13. Every Simulator iPad since iOS 13.4 until the last iOS 13.从iOS 13.4到最后一个 iOS 13 的每个 iPad。 从iOS 13.4到最后一个 iOS 13 的每个模拟器 iPad。
I never saw this bug on iPhone.我从未在 iPhone 上看到过这个错误。
My set up for testing: MacOS Catalina 10.15.6, xCode 11.7 , Simulator iPad mini 2019 5-gen iOS 13.7, iPad 2018 6-gen iOS 13.7.我的测试设置:MacOS Catalina 10.15.6、 xCode 11.7 、Simulator iPad mini 2019 5-gen iOS 13.7、iPad 2018 6-gen iOS 13.7。
Upd 26.10.2020 . 2020 年 10 月 26 日更新。 Also, I try to use xCode 12.0.1 on MacOS Catalina 10.15.7, iPad 2018 6-gen iOS 13.7.
此外,我尝试在 MacOS Catalina 10.15.7、iPad 2018 6 代 iOS 13.7 上使用 xCode 12.0.1 。 I retested, looks like the bug still available on iOS 13.4-13.7 , but is gone for iOS 14 .
我重新测试了,看起来这个错误在iOS 13.4-13.7上仍然可用,但在iOS 14 上已经消失了。 Good decision for iOS 13 I didn't find.
我没有找到适用于 iOS 13 的好决定。
TestCrashIPAD
) with List, ForEach and dynamic sections (source code below).TestCrashIPAD
)与 List、ForEach 和动态部分(下面的源代码)一起使用。TestCrashIPAD
).TestCrashIPAD
)。I get crash on AppDelegate with: Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
我在 AppDelegate 上崩溃了:
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
I investigated a little bit, and found: this bug reproducible since iOS 13.4.我调查了一下,发现:这个错误自 iOS 13.4 以来可重现。 Also with iOS 13.4 there is a View Modifier onDrag (link) .
在 iOS 13.4 中还有一个View Modifier onDrag (link) 。 May be it's somehow connected, because in call stack I see:
可能是以某种方式连接的,因为在调用堆栈中我看到:
UIDragInteractionLongPressDriver
UIGestureRecognizer
May be something wrong with dynamic sections array, because I see:动态部分数组可能有问题,因为我看到:
SwiftUI.Sections.rowIDs(forSectionAt: Swift.Int)
SwiftUI.ListCoreDataSource.rowIndex(at: Foundation.IndexPath)
How to fix this issue?如何解决这个问题? How to work around without crash in this case?
在这种情况下如何解决而不崩溃? Please, say any idea.
请说任何想法。
Please have a look the source code:请看一下源代码:
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.