当用户在新的 iOS DateTimePicker 中点击 "Reset" 时崩溃

Crash when user tap "Reset" in new iOS DateTimePicker

我在 WebView 中用日期字段打开我们的 HTML,但是在 iOS 14 当用户点击按钮时 reset 我遇到了崩溃

Thread 1: EXC_BAD_ACCESS (code=2, address=0x36b90b7b50)

#0  0x00000001be6a60f8 in objc_msgSend ()
#1  0x00000001b680073c in -[WKDateTimePicker setDateTimePickerToInitialValue] ()
#2  0x00000001b6800134 in -[WKDateTimePicker reset:] ()

我认为是 Apple Crash,但我该如何解决这种情况?也许有办法修复 HTML,或者在 iOS 方面做一些事情 screen example

one more link

我用 swizzling 方法解决了这个问题

let originalSelector = #selector(app.sendAction(_:to:from:for:))
let swizzledSelector = #selector(app.log_sendAction(_:to:from:for:))

并在 log_sendAction 我检查

  • if iOS Version .available(14..<15)
  • and if action: Selector .contains(find: "reset:")
  • and if to target: Any?.contains(find: "WKDateTimePicker")
  • 然后 skeep call original originalSelector