從Xcode 11.1升級到Xcode 11.2後,由於_UITextLayoutView,應用程序崩潰

本文翻譯自:After upgrading to Xcode 11.2 from Xcode 11.1, app crashes due to _UITextLayoutView

After upgrading to Xcode 11.2 from Xcode 11.1 my app crashes: 從Xcode 11.1升級到Xcode 11.2之後,我的應用崩潰了:

*** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named _UITextLayoutView because no class named _UITextLayoutView was found; ***由於未捕獲的異常'NSInvalidUnarchiveOperationException'而終止應用程序,原因:'由於未找到名爲_UITextLayoutView的類,因此無法實例化名爲_UITextLayoutView的類; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target)' 該類需要在源代碼中定義或從庫中鏈接(確保該類是正確目標的一部分)'

Why is this happening? 爲什麼會這樣呢? How can I prevent this crash? 如何防止此崩潰?


#1樓

參考:https://stackoom.com/question/3y7O3/從Xcode-升級到Xcode-後-由於-UITextLayoutView-應用程序崩潰


#2樓

This is because of xCode update to 11.2 version. 這是因爲xCode更新到11.2版本。 Try with an older xCode version to see if is still crashing. 嘗試使用較舊的xCode版本,以查看是否仍然崩潰。 Apple don't have a fix for this yet. 蘋果尚未對此進行修復。


#3樓

在低於iOS 13的版本上進行測試時,它與通過Storyboard添加的UITextView有關。我認爲這是Xcode 11.2中的錯誤,因爲以前的版本沒有問題。


#4樓

在iOS 13.1上看到相同的問題...在iOS 13.2上工作正常


#5樓

As a "quick" fix you can add the UITextView directly from the code and not via IB. 作爲「快速」修復,您可以直接從代碼中而不是通過IB添加UITextView At least it worked for me. 至少對我有用。 Though from my point of view it's better to rollback to previous Xcode/wait for the new one. 雖然從我的角度來看,最好回滾到以前的Xcode /等待新的Xcode。


#6樓

Update: Fixed! 更新:固定! 🎉🎊 🎉🎊

The ONLY Solution is to update 唯一的解決方案是更新

This bug is fixed in Xcode 11.2.1. 錯誤已在Xcode 11.2.1中修復 So you can download and use it from here. 因此,您可以從此處下載並使用它。

Storyboards containing a UITextView will no longer cause the app to crash on operating system versions earlier than iOS 13.2, tvOS 13.2, or macOS 10.15.2. 包含UITextView的情節提要板將不再導致應用程序在iOS 13.2,tvOS 13.2或macOS 10.15.2之前的操作系統版本上崩潰。 (56808566, 56873523) (56808566,56873523)


Xcode 11.2 is deprecated by Apple on November 5, 2019 Apple已於2019年11月5日棄用Xcode 11.2

if you ever try to submit your app that build with Xcode 11.2 to the AppStore, you will be rejected: 如果您曾經嘗試將使用Xcode 11.2構建的應用提交到AppStore,則將被拒絕:

App Store Connect Operation Warning App Store Connect操作警告

WARNING ITMS-90703 : "Deprecated Xcode Build. Due to resolved app archives issues, we have deprecated Xcode 11.2 on November 5, 2019. Download Xcode 11.2.1 or newer, rebuild your app and resubmit." 警告ITMS-90703 :「不建議使用Xcode Build。由於已解決的應用程序存檔問題,我們已於2019年11月5日棄用了Xcode 11.2。下載Xcode 11.2.1或更高版本,重建您的應用程序並重新提交。」

So all workarounds done with the Xcode 11.2 is useless 因此,使用Xcode 11.2完成的所有變通辦法都沒有用


It's a bug for Xcode 11.2, and fixed in Xcode 11.2.1. 這是Xcode 11.2的錯誤,已在Xcode 11.2.1中修復。

Solution(s) 解決方案

Roll back to previous Xcode release version from: Rollback is not an option anymore and AppStore will reject any build with Xcode below 11.2.1 take a look at this 回滾到之前的Xcode 發佈版本從:回滾是不是一種選擇了和AppStore的將拒絕任何的Xcode構建以下11.2.1 看看這個

https://developer.apple.com/services-account/download?path=/Developer_Tools/Xcode_11.1/Xcode_11.1.xip https://developer.apple.com/services-account/download?path=/Developer_Tools/Xcode_11.1/Xcode_11.1.xip

Note that you should use Safari to download it and you must first login to Apple developer portal . 請注意,您應該使用Safari下載它,並且必須首先登錄到Apple開發人員門戶

You can find all other Xcode versions and other resources link (including release and beta versions) here at https://developer.apple.com/download/more 您可以在https://developer.apple.com/download/more上找到所有其他Xcode版本和其他資源鏈接(包括髮行版和Beta版)。

The workaround 解決方法

This is very hard but working workaround. 這非常困難,但是可以解決。 Replace all UITextView s in storyboard s and Xib s with the pure code version. 純代碼版本替換StoryboardXib中的所有UITextView


Note that this bug is found and fixed by Apple 請注意,錯誤已由Apple找到並修復。

固定

Also earlier, the bug was confirmed by Apple Staff edford 同樣, 該錯誤已由Apple Staff edford確認

確認書


For those with iOS 13.2 and can not use Xcode 11.1 anymore: 對於使用iOS 13.2且無法再使用Xcode 11.1的用戶:

  1. Update macOS to 10.15.1 or later 將macOS更新到10.15.1或更高版本
  2. Install Xcode 11.2.1 or later 安裝Xcode 11.2.1或更高版本
  3. It should be work now on the updated device. 現在應該可以在更新的設備上工作了。

For those with storyboard: 對於那些擁有分鏡腳本的用戶:

  1. Subclass UITextView 子類UITextView
  2. Assign it to all UITextView objects 將其分配給所有UITextView對象
  3. Don't forget to update any property changes that may lose in the subclassing. 不要忘記更新可能在子類中丟失的任何屬性更改。

For those comfortable with method swizzling (Objc and dynamic behavior) 對於那些習慣方法混亂的人(OBJC和動態行爲)

Head to the @aftab muhammed khan answer for Objective-C and @MikRo answer for Swift adapted version 轉到Objective-C@aftab muhammed khan 答案Swift適應版本的 @MikRo 答案

Just don't do it anymore: 只是不再這樣做:

Even if these last two swizzling workarounds are not using Apple private API , they will be rejected in AppStore because Apple will not accept builds with Xcode versions under 11.2.1 ! 即使這最後兩個麻煩的解決方法沒有使用Apple私有API ,它們也會在AppStore中被拒絕 ,因爲Apple不會接受11.2.1下的Xcode版本的構建

And once again: 再一次:

Xcode 11.2 is deprecated by Apple on November 5, 2019 Apple已於2019年11月5日棄用Xcode 11.2