简体   繁体   中英

Why iOS app crashed when keyboard is tapped?

My app is crashing when the keyboard is tapped, I select the textfield, the keyboard open properly, but once the keyboard is tapped (any key) the crash happen, giving the log below.

Im running the app on iPhone 8 with iOS 15 RC, from Xcode 13 RC. In any other device with iOS 14 (not matter the version) is working properly.

Debug Console error

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

Im not using the stringByTrimmingCharactersInSet function, so im guessing is a system call. The libraries that I'm using are cocoa pods.

You can find the entire crash log on this question on apple forums: https://developer.apple.com/forums/thread/689868

Debug navigator

The warning in the last task from the image says:

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

调试导航器

Code for initialisation and view controller

It's a big code but I reduce to this only to test the textfield.

Initialisation of controller from app delegate

import UIKit

@UIApplicationMain class 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
}... }

View Controller content

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)
            ])
        }
    }

Pods: Firebase Auth, RemoteConfig, Analytics, GoogleSignIn, Stripe, Intercom, lottie

Please check your info.plist

If you see this, chanage it to String

from

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

to

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

Well at the end I find a solution, but Im quite sure that was too complicated.

My app was generated with Xcode 10, so I decided to create a new project with the Xcode 13 and move all the folders and configurations to this new project, that solved my error and any other problem that I was having.

If anybody had a better solution please shared.

I had the same problem and found a solution. Go to the info.plist file and right click -> Open as Source File. Delete the below lines.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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