iOS 17.4模拟器点击UITextField触发CLLocationButton崩溃问题咨询
iOS 17.4模拟器点击UITextField崩溃问题
环境信息
- Xcode 15.3
- MacBook Air M1(8GB)
- macOS Sonoma 14.4
- iOS 17.4模拟器
- 搭载iOS 15.8的iPhone SE第一代真机无此问题
崩溃现象
点击UITextField时App直接崩溃,错误提示:
Thread 1: "*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: arrow.uturn.forward)"
复现代码
import UIKit import CoreLocationUI class ViewController: UIViewController { let textField: UITextField = { let tf = UITextField() tf.backgroundColor = .systemGray6 tf.placeholder = "Tap me" tf.leftView = UIView(frame: .init(x: 0, y: 0, width: 8, height: 0)) tf.leftViewMode = .always tf.layer.cornerRadius = 11 return tf }() let locationButton = CLLocationButton() override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .systemBackground view.addSubview(textField) view.addSubview(locationButton) textField.translatesAutoresizingMaskIntoConstraints = false locationButton.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ textField.centerXAnchor.constraint(equalTo: view.centerXAnchor), textField.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 8), textField.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.85), textField.heightAnchor.constraint(equalToConstant: 44), locationButton.centerXAnchor.constraint(equalTo: view.centerXAnchor), locationButton.topAnchor.constraint(equalTo: textField.bottomAnchor, constant: 8), locationButton.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.85), locationButton.heightAnchor.constraint(equalToConstant: 44), ]) } }
控制台完整日志
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: arrow.uturn.forward)' *** First throw call stack: ( 0 CoreFoundation 0x00000001804ae138 __exceptionPreprocess + 172 1 libobjc.A.dylib 0x0000000180087db4 objc_exception_throw + 56 2 CoreFoundation 0x000000018051e88c -[__NSDictionaryM setObject:forKey:] + 1232 3 UIKitCore 0x00000001856c0f44 +[UIAssistantBarButtonItemProvider configuredSymbolImageWithName:size:] + 344 4 UIKitCore 0x00000001856c00bc +[UIAssistantBarButtonItemProvider barButtonItemForAssistantItemStyle:target:forcePlainButton:] + 2120 5 UIKitCore 0x00000001856c1200 +[UIAssistantBarButtonItemProvider defaultSystemLeadingBarButtonGroupsForItem:] + 204 6 UIKitCore 0x00000001856c1754 +[UIAssistantBarButtonItemProvider systemDefaultAssistantItem] + 48 7 UIKitCore 0x0000000185417e0c -[UIResponder(UIResponderInputViewAdditions) inputAssistantItem] + 64 8 UIKitCore 0x0000000185717710 -[UITextField inputAssistantItem] + 64 9 UIKitCore 0x0000000185417d4c _UIResponderFindInputAssistantItem + 44 10 UIKitCore 0x0000000184d79c18 -[UISystemInputAssistantViewController isVisibleWhenMinimized] + 96 11 UIKitCore 0x000000018523c12c +[UIPeripheralHost(UIKitInternal) endPlacementForInputViewSet:windowScene:] + 1292 12 UIKitCore 0x0000000184e0b2d0 -[UIKeyboardSceneDelegate prepareToMoveKeyboardForInputViewSet:animationStyle:] + 192 13 UIKitCore 0x0000000184e0a060 -[UIKeyboardSceneDelegate setKeyWindowSceneInputViews:animationStyle:] + 1396 14 UIKitCore 0x0000000184e09ab8 -[UIKeyboardSceneDelegate setInputViews:animationStyle:] + 132 15 UIKitCore 0x0000000184e0aaa4 -[UIKeyboardSceneDelegate setInputViews:animated:] + 72 16 UIKitCore 0x0000000184e0aaf4 -[UIKeyboardSceneDelegate setInputViews:] + 52 17 UIKitCore 0x0000000184e081f0 __102-[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:force:fromBecomeFirstResponder:]_block_invoke.484 + 24 18 UIKitCore 0x00000001852386e0 __65-[UIPeripheralHost(UIKitInternal) queueDelayedTask:forKey:delay:]_block_invoke + 156 19 libdispatch.dylib 0x00000001016fd73c _dispatch_client_callout + 16 20 libdispatch.dylib 0x0000000101700c14 _dispatch_continuation_pop + 756 21 libdispatch.dylib 0x00000001017164e0 _dispatch_source_invoke + 1736 22 libdispatch.dylib 0x000000010170d2a8 _dispatch_main_queue_drain + 892 23 libdispatch.dylib 0x000000010170cf1c _dispatch_main_queue_callback_4CF + 40 24 CoreFoundation 0x000000018040e9a0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 25 CoreFoundation 0x00000001804090b8 __CFRunLoopRun + 1936 26 CoreFoundation 0x0000000180408514 CFRunLoopRunSpecific + 572 27 GraphicsServices 0x000000018ef06ae4 GSEventRunModal + 160 28 UIKitCore 0x00000001853e8040 -[UIApplication _run] + 868 29 UIKitCore 0x00000001853ebcc8 UIApplicationMain + 124 30 UIKitCore 0x000000018488c1cc __swift_destroy_boxed_opaque_existential_1Tm + 10048 31 Crash_CLLocationButton 0x000000010057044c $sSo21UIApplicationDelegateP5UIKitE4mainyyFZ + 120 32 Crash_CLLocationButton 0x00000001005703c4 $s22Crash_CLLocationButton11AppDelegateC5$mainyyFZ + 44 33 Crash_CLLocationButton 0x00000001005704c8 main + 28 34 dyld 0x00000001005d1544 start_sim + 20 35 ??? 0x00000001006e60e0 0x0 + 4302201056 36 ??? 0x027c800000000000 0x0 + 179158822676332544 ) libc++abi: terminating due to uncaught exception of type NSException
问题分析与临时解决
从崩溃栈可以看出,问题根源是iOS 17.4模拟器的UIKit内部在加载系统符号arrow.uturn.forward时返回nil,导致设置字典对象时触发异常。结合真机无此问题的表现,这基本可以确定是模拟器专属Bug。
临时规避方案:禁用UITextField的系统输入助理栏按钮,在viewDidLoad中添加以下代码:
textField.inputAssistantItem.leadingBarButtonGroups = [] textField.inputAssistantItem.trailingBarButtonGroups = []
内容的提问来源于stack exchange,提问作者Filippo
相关产品推荐
相关产品推荐

