Swift: iOS 12.2 应用启动时崩溃

Swift: iOS 12.2 Crash of the app on launch

更新 Xcode 和 swift 5 后,在 iOS 12.2 上启动模拟器后,我的应用程序在启动时崩溃。但在 ios 的早期版本(如 12.0)中,应用程序可以正常工作。我在真实设备 ios 12.0.1 上启动应用程序并且应用程序正常运行,然后在 iOS 设备 12.2 上启动应用程序并且应用程序崩溃

我不知道它是否相关,但在控制台中我收到以下消息:

objc[39432]: Swift class extensions and categories on Swift classes are not allowed to have +load methods

然后 Xcode 重定向到 0_abort_with_payload:

    libsystem_kernel.dylib`__abort_with_payload:
    0x11365200c <+0>:  movl   [=12=]x2000209, %eax          ; imm = 0x2000209 
    0x113652011 <+5>:  movq   %rcx, %r10
    0x113652014 <+8>:  syscall 
->  0x113652016 <+10>: jae    0x113652020               ; <+20>
    0x113652018 <+12>: movq   %rax, %rdi
    0x11365201b <+15>: jmp    0x113634457               ; cerror_nocancel
    0x113652020 <+20>: retq   
    0x113652021 <+21>: nop    
    0x113652022 <+22>: nop    
    0x113652023 <+23>: nop    

问题已解决;我使用 Swinject CocoaPod,所以在 Podfile 中我更新了该 pod 的相应行:

pod 'SwinjectStoryboard', :git => 'https://github.com/mdyson/SwinjectStoryboard.git', :branch => 'master'`

您提到的错误非常相关:)

objc[39432]: Swift class extensions and categories on Swift classes are not allowed to have +load methods

我找不到它发生的原因,但问题似乎是你,或者你正在使用的某些依赖项正在使用不再允许的静态 load 方法。

您可以尝试一些方法

  1. 检查代码中的 load 个函数
  2. 查看您的依赖项,看看是否有任何可以解决此问题的更新

thread on twitter 也可用于查明问题可能出在哪里。正如建议的那样,尝试在启动应用程序时添加 OBJC_PRINT_LOAD_METHODS=YES,因为这应该会为您提供更多线索。

希望对您有所帮助。