1

Xcode 13.0、Swift 5.5、iOS 15.0.2

请裸露我糟糕的调试技巧。

一旦我尝试在我的应用程序的文本字段中输入内容,它就会抛出 aNSInvalidArgumentException并打印日志:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[__NSSingleObjectArrayI stringByTrimmingCharactersInSet:]: 
unrecognized selector sent to instance 0x281a074b0'

*** First throw call stack:
(0x18535dcac 0x19c3cc758 0x18542d6d0 0x1852f7edc 0x1852f714c 0x187777400 0x187b22ee8 
0x10566e1c8 0x10566fb1c 0x18777ac48 0x187c02f50 0x10566e1c8 0x10566fb1c 0x187699e84 
0x187699ce8 0x187698b58 0x187b173fc 0x10566e1c8 0x10566fb1c 0x187b9f0d4 0x1884cf17c 
0x1884db210 0x1884dacd8 0x1884ce794 0x1884cd90c 0x1884dc0ec 0x1884dc0ec 0x1884dc0ec 
0x1884dc0ec 0x1884dc0ec 0x1884dc0ec 0x1884dc0ec 0x1884dc0ec 0x1884dc0ec 0x1884dc0ec 
0x1884dc0ec 0x1884dc0ec 0x1884dc0ec 0x1884dc0ec 0x1884dc0ec 0x1884dc0ec 0x1884dc0ec 
0x1884cd978 0x18830689c 0x18826cc74 0x18830f8c4 0x18830f9d4 0x187ba4a70 0x187a5bfd4 
0x18777d948 0x18830f60c 0x18779486c 0x1877c472c 0x187969160 0x187799380 0x18778e130 
0x18779365c 0x18537e220 0x18538e248 0x1852d15e8 0x1852d6a18 0x1852e9d8c 0x19f3f69a0 
0x187b1efa8 0x1878b322c 0x19b4f3e80 0x104486c24 0x104844190)

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

-[__NSSingleObjectArrayI stringByTrimmingCharactersInSet:]我在此处设置了一个符号断点(如何调试“无法识别的选择器发送到实例”错误)。但据我所知,没有达到这个断点(?)

在 Xcode Debug navigator 中,应用程序在此处崩溃:#68 0x0000000104486bd4 in static AppDelegate.$main() [inlined],根据第 9 行:

MyApp`main:
    9. 0x104486bd4 <+28>:  bl     0x10451bbd0               ; symbol stub for: static Swift.CommandLine.unsafeArgv.getter : Swift.UnsafeMutablePointer<Swift.Optional<Swift.UnsafeMutablePointer<Swift.Int8>>>
 

我的 AppDelegate:

import UIKit
import Firebase
import FirebaseUI
import FBSDKCoreKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var orientationLock = UIInterfaceOrientationMask.all

    func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        return self.orientationLock
    }

    struct AppUtility {
        static func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
            if let delegate = UIApplication.shared.delegate as? AppDelegate {
                delegate.orientationLock = orientation
            }
        }

        static func lockOrientation(_ orientation: UIInterfaceOrientationMask, andRotateTo rotateOrientation:UIInterfaceOrientation) {
            self.lockOrientation(orientation)
            UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation")
        }
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
        //Initialize and configure Firebase
        FirebaseApp.configure()

        // Initialize Facebook SDK
        ApplicationDelegate.shared.application(application,didFinishLaunchingWithOptions: launchOptions) 
    
        return true
    }

    func application(_ app: UIApplication, open url: URL, options: UIApplication.OpenURLOptionsKey : Any]) -> Bool {
        let sourceApplication = options[UIApplication.OpenURLOptionsKey.sourceApplication] as! String?
    
        // FirebaseUI URL handling
        if FUIAuth.defaultAuthUI()?.handleOpen(url, sourceApplication: sourceApplication) ?? false {
            return true
        }
        // other URL handling goes here.
        return false
    }

    // MARK: UISceneSession Lifecycle

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }

    func applicationWillTerminate(_ application: UIApplication) {}
}

将标记放在文本字段中时,在开始输入之前,日志打印Writing analzed variants. 我以前从未见过,但根据此(Xcode 日志“Writing analzed variables”)可以忽略它。

我在启动应用程序时也在日志中看到了这一点,这是我以前从未见过的。不知道有没有帮助:

[] __nwlog_err_simulate_crash simulate crash already simulated "nw_hash_table_apply called with null table"
[] nw_hash_table_apply called with null table, dumping backtrace:
    [arm64] libnetcore-2736.12.1
0   libnetwork.dylib                    0x00000001867cb2f0 __nw_create_backtrace_string + 116
1   libnetwork.dylib                    0x0000000185fa9820 nw_hash_table_apply + 2676
2   libnetwork.dylib                    0x00000001864f4450 EE6D5599-5B6E-3AAC-ABC7-05F56B4EE2FB + 6030416
3   libnetwork.dylib                    0x00000001864d0a9c EE6D5599-5B6E-3AAC-ABC7-05F56B4EE2FB + 5884572
4   CFNetwork                           0x0000000185ce152c _CFURLStorageSessionCopyIdentifier + 14364
5   libnetwork.dylib                    0x00000001860c3eb8 EE6D5599-5B6E-3AAC-ABC7-05F56B4EE2FB + 1638072
6   libdispatch.dylib                   0x00000001032d494c _dispatch_call_block_and_release + 24
7   libdispatch.dylib                   0x00000001032d61c8 _dispatch_client_callout + 16
8   libdispatch.dylib                   0x00000001032df560 _dispatch_workloop_invoke + 2448
9   libdispatch.dylib                   0x00000001032e9630 _dispatch_workloop_worker_thread + 852
10  libsystem_pthread.dylib             0x00000001dece2f38 _pthread_wqthread + 284
11  libsystem_pthread.dylib             0x00000001dece2aa4 start_wqthread + 8

更新 - TEXTFIELD CONFIG 问题在于应用程序中的所有文本字段,甚至是 FirebaseUI 中的电子邮件地址文本字段(我根本没有手动配置)。这让我觉得这不是关于文本字段配置,而是键盘问题?这有意义吗?我该如何调试?

无论如何,我创建的文本字段是在情节提要中创建的。在每个视图控制器中,我都有一些委托方法;textFieldDidBeginEditing(_:),textFieldShouldReturn(_:)textFieldDidEndEditing(_:). 我可以知道当用户点击文本字段时正在调用 textFieldDidBeginEditing。但是,一旦按下第一个键盘字母,就会抛出异常。

键盘是默认的,textField contentType 是未指定的。不知道这是否相关。

更新 我没有对我的代码做任何事情,但是在更新到 iOS 15.2 之后,错误就消失了!?有任何想法吗?

4

0 回答 0