繁体   English   中英

为什么点击键盘时 iOS 应用程序崩溃?

[英]Why iOS app crashed when keyboard is tapped?

我的应用程序在敲击键盘时崩溃,我选择了文本字段,键盘正确打开,但是一旦敲击键盘(任意键),就会发生崩溃,并给出以下日志。

我在 iPhone 8 上使用 iOS 15 RC 运行该应用程序,来自 Xcode 13 RC。 在任何其他装有 iOS 14 的设备上(无论版本如何)都可以正常工作。

调试控制台错误

2021-09-14 14:11:12.860707+0100 BonnetDriverDev[3595:649035] -[__NSArray0 stringByTrimmingCharactersInSet:]: unrecognized selector sent to instance 0x1f5c13500
2021-09-14 14:11:12.864293+0100 BonnetDriverDev[3595:649035] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArray0 stringByTrimmingCharactersInSet:]: unrecognized selector sent to instance 0x1f5c13500'
*** First throw call stack:
(0x180cddcac 0x197d0a748 0x180dad6d0 0x180c77edc 0x180c7714c 0x1830f752c 0x1834a2360 0x102f0e1c8 0x102f0fb1c 0x1830fad74 0x1835812a0 0x102f0e1c8 0x102f0fb1c 0x183019fc4 0x183019e28 0x183018c98 0x183496874 0x102f0e1c8 0x102f0fb1c 0x18351e144 0x183e49624 0x183e556b8 0x183e55180 0x183e48c3c 0x183e47db4 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e56594 0x183e47e20 0x183c81fac 0x183be8384 0x183c8afd4 0x183c8b0e4 0x183523ae0 0x1833dad2c 0x1823cc98c 0x180cfe220 0x180d0e248 0x180c515e8 0x180c56a18 0x180c69d8c 0x19ad2a9a0 0x18349e420 0x183231e18 0x100e585a4 0x101f0c190)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArray0 stringByTrimmingCharactersInSet:]: unrecognized selector sent to instance 0x1f5c13500'
terminating with uncaught exception of type NSException

我没有使用stringByTrimmingCharactersInSet函数,所以我猜是系统调用。 我使用的库是可可豆荚。

你可以在苹果论坛上找到关于这个问题的整个崩溃日志: https : //developer.apple.com/forums/thread/689868

调试导航器

图像中最后一个任务中的警告说:

Thread 1: "-[__NSArray0 stringByTrimmingCharactersInSet:]: unrecognized selector sent to instance 0x1fa3a3500"

调试导航器

初始化和视图控制器的代码

这是一个很大的代码,但我减少到这个只是为了测试文本字段。

从应用程序委托初始化控制器

导入 UIKit

@UIApplicationMain 类 AppDelegate: UIResponder, UIApplicationDelegate {

public var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
    let vc = TestViewController(nibName: nil, bundle: nil)
  
    self.window = UIWindow(frame: UIScreen.main.bounds)
    self.window?.rootViewController = vc
    self.window?.makeKeyAndVisible()
    
    return true
}... }

查看控制器内容

import UIKit

    class TestViewController: UIViewController {
        
        private var textField: UITextField {
            var v = UITextField()
            v.translatesAutoresizingMaskIntoConstraints = false
            return v
        }
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            self.setup()
        }
        
        private func setup() {
            self.view.addSubview(textField)
            
            NSLayoutConstraint.activate([
                self.textField.centerYAnchor.constraint(equalTo: self.view.centerYAnchor),
                self.textField.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
                self.textField.heightAnchor.constraint(equalToConstant: 50),
                self.textField.widthAnchor.constraint(equalTo: self.view.widthAnchor, multiplier: 0.8)
            ])
        }
    }

Pod:Firebase Auth、RemoteConfig、Analytics、GoogleSignIn、Stripe、Intercom、lottie

请检查您的 info.plist

如果你看到这个,把它改成字符串

<key>CFBundleDisplayName</key>
<false/>

<key>CFBundleDisplayName</key>
<string>YourAppName</string>

最后我找到了一个解决方案,但我很确定那太复杂了。

我的应用程序是用 Xcode 10 生成的,所以我决定用 Xcode 13 创建一个新项目,并将所有文件夹和配置移动到这个新项目中,这解决了我的错误和我遇到的任何其他问题。

如果有人有更好的解决方案,请分享。

我遇到了同样的问题并找到了解决方案。 转到 info.plist 文件并右键单击 -> 作为源文件打开。 删除以下几行。

<key>CFBundleDisplayName</key>
<array> </array>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM