簡體   English   中英

從 Xcode 11.1 升級到 Xcode 11.2 后,應用程序因 _UITextLayoutView 而崩潰

[英]After upgrading to Xcode 11.2 from Xcode 11.1, app crashes due to _UITextLayoutView

從 Xcode 11.1 升級到 Xcode 11.2 后,我的應用程序崩潰:

*** 由於未捕獲的異常“NSInvalidUnarchiveOperationException”而終止應用程序,原因:“無法實例化名為 _UITextLayoutView 的 class,因為找不到名為 _UITextLayoutView 的 class; class 需要在源代碼中定義或從庫中鏈接(確保 class 是正確目標的一部分)'

為什么會這樣? 我怎樣才能防止這種崩潰?

更新:已修復!

唯一的解決方案是更新

錯誤已在 Xcode 11.2.1 中修復 所以你可以從這里下載和使用它。

包含 UITextView 的 Storyboard 將不再導致應用在早於 iOS 13.2、tvOS 13.2 或 macOS 10.15.2 的操作系統版本上崩潰。 (56808566, 56873523)


Xcode 11.2 於 2019 年 11 月 5 日被 Apple 棄用

如果您嘗試將使用 Xcode 11.2 構建的應用程序提交到 AppStore,您將被拒絕:

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."

因此,使用 Xcode 11.2 完成的所有解決方法都是無用


這是 Xcode 11.2 的錯誤,並在 Xcode 11.2.1 中修復。

解決方案

回滾到以前的 Xcode發布版本:回滾不再是一種選擇,AppStore 將拒絕任何低於 11.2.1 的 Xcode的構建看看這個

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

請注意,您應該使用 Safari 下載它,並且您必須先登錄 Apple 開發者門戶

您可以在https://developer.apple.com/download/more找到所有其他 Xcode 版本和其他資源鏈接(包括發行版和測試版)

解決方法

這是非常困難但可行的解決方法。 storyboardXib中的所有UITextView替換為純代碼版本。


請注意,錯誤由 Apple 發現並修復

固定的

同樣早些時候, Apple Staff edford確認了該錯誤

確認


對於那些使用 iOS 13.2 並且不能再使用 Xcode 11.1 的用戶:

  1. 將 macOS 更新到 10.15.1 或更高版本
  2. 安裝 Xcode 11.2.1 或更高版本
  3. 它現在應該可以在更新的設備上使用。

對於那些有 storyboard 的人:

  1. 子類UITextView
  2. 將其分配給所有UITextView對象
  3. 不要忘記更新可能在子類化中丟失的任何屬性更改。

對於那些對方法調配(Objc 和動態行為)感到滿意的人

前往 Objective-C 的@aftab muhammed khan答案Swift 改編版的@MikRo答案

只是不要再這樣做了:

即使這最后兩個 swizzling 變通辦法沒有使用Apple 私有 API ,它們也會在 AppStore 中被拒絕,因為Apple 不會接受 Xcode 版本低於 11.2.1 的構建

再一次:

Xcode 11.2 於 2019 年 11 月 5 日被 Apple 棄用

祝賀

Xcode (11.2.1) 的新版本現已推出,這是解決此問題的最佳方法。

解決方法

@Mojtaba Hosseini 我提出的解決方案來自我對 StackOverflow 開發人員的幫助和參與。 你我和這里所有開發者的rest都已經知道,當蘋果宣布新版本時,這個問題就會消失。

但除了一切

上述解決方案肯定被 Apple Review 接受,因為根本不涉及私有 API。 這種方法與創建屬性非常相似,例如

@interface UITextView(布局)

或者

UITextView+Layout.h

因此,當您創建屬性時,您將直接使用 APPLE 私有組件並根據您的依賴或要求重新調制它們。

簡單示例是 AMFNetworking 類

- (void)setImageWithURL:(NSURL *)url {
    [self setImageWithURL:url placeholderImage:nil];
}

希望我完成了指控

下面的答案只是我方面的一些幫助,以使開發人員能夠繼續開發,因為我們最初建議開發人員回滾 Xcode。 再次下載 8 GB Xcode 是一種不好的做法,因為我們都知道 Xcode 的新版本即將發布。

雖然它已在 Xcode 11.2.1 中修復,但我為 Xcode 11.2 提供了一種解決方案,您可以通過它擺脫這種崩潰:

*** 由於未捕獲的異常“NSInvalidUnarchiveOperationException”而終止應用程序,原因:“無法實例化名為 _UITextLayoutView 的 class,因為找不到名為 _UITextLayoutView 的 class; class 需要在源代碼中定義或從庫中鏈接(確保 class 是正確目標的一部分)'

解決方案

Go 到 Build Setting 搜索“DEAD_CODE_STRIPPING”並將其設置為 NO

DEAD_CODE_STRIPPING = NO

然后

創建文件 UITextViewWorkaround

UITextViewWorkaround.h

    #import <Foundation/Foundation.h>


    @interface UITextViewWorkaround : NSObject
    + (void)executeWorkaround; 
@end

UITextViewWorkaround.m

#import "UITextViewWorkaround.h"
#import  <objc/runtime.h>



    @implementation UITextViewWorkaround

    + (void)executeWorkaround {
        if (@available(iOS 13.2, *)) {
        }
        else {
            const char *className = "_UITextLayoutView";
            Class cls = objc_getClass(className);
            if (cls == nil) {
                cls = objc_allocateClassPair([UIView class], className, 0);
                objc_registerClassPair(cls);
    #if DEBUG
                printf("added %s dynamically\n", className);
    #endif
            }
        }
    }

    @end

在應用程序委托中執行它

#import "UITextViewWorkaround.h"

        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
            // Override point for customization after application launch.

            [UITextViewWorkaround executeWorkaround];
    return yes;
    }

編譯代碼,您將擁有一個正在運行的應用程序:)

該問題已在 Xcode 11.2.1 中修復。

編輯:隨着修復程序現已發布,您應該切換到該 Xcode 版本並注釋掉此解決方法。 正如 Mojtaba Hosseini 在他的回答中提到的那樣:

...這最后兩個 swizzling 變通辦法正在使用 Apple 私有 API 並且將被 Apple 審查拒絕!

在 Apple 發布修復程序之前,這是繼續開發和測試的一個很好的解決方法。


對於 Xcode 11.2,基於 Aftab Muhammed Khan 的想法並在 John Nimis 的幫助下,我剛剛測試了以下代碼。

無需更改 storyboard 文件!

編輯了我的 AppDelegate.swift 文件並添加了這個 class

//******************************************************************
// MARK: - Workaround for the Xcode 11.2 bug
//******************************************************************
class UITextViewWorkaround: NSObject {

    // --------------------------------------------------------------------
    // MARK: Singleton
    // --------------------------------------------------------------------
    // make it a singleton
    static let unique = UITextViewWorkaround()

    // --------------------------------------------------------------------
    // MARK: executeWorkaround()
    // --------------------------------------------------------------------
    func executeWorkaround() {

        if #available(iOS 13.2, *) {

            NSLog("UITextViewWorkaround.unique.executeWorkaround(): we are on iOS 13.2+ no need for a workaround")

        } else {

            // name of the missing class stub
            let className = "_UITextLayoutView"

            // try to get the class
            var cls = objc_getClass(className)

            // check if class is available
            if cls == nil {

                // it's not available, so create a replacement and register it
                cls = objc_allocateClassPair(UIView.self, className, 0)
                objc_registerClassPair(cls as! AnyClass)

                #if DEBUG
                NSLog("UITextViewWorkaround.unique.executeWorkaround(): added \(className) dynamically")
               #endif
           }
        }
    }
}

並在對“didFinishLaunchingWithOptions”的委托調用中調用解決方法

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    // Override point for customization after application launch.

    // This is the workaround for Xcode 11.2
    UITextViewWorkaround.unique.executeWorkaround()
}

我已經將 khan 的 Obj-C 解決方案改編為Swift

import UIKit

@objc
class UITextViewWorkaround : NSObject {

    static func executeWorkaround() {
        if #available(iOS 13.2, *) {
        } else {
            let className = "_UITextLayoutView"
            let theClass = objc_getClass(className)
            if theClass == nil {
                let classPair: AnyClass? = objc_allocateClassPair(UIView.self, className, 0)
                objc_registerClassPair(classPair!)
            }
        }
    }

}

AppDelegate中的didFinishLaunchingWithOptions結束時調用它。

謝謝@Aftab!

更快的修復:

///Substitute class for _UITextLayoutView bug
class FixedTextView: UITextView {
    required init?(coder: NSCoder) {
        if #available(iOS 13.2, *) {
            super.init(coder: coder)
        }
        else {
            let rect = CGRect(origin: .zero, size: CGSize(width: 100, height: 44*3))
            super.init(frame: rect, textContainer: nil)
        }
    }
}

在某處添加此代碼,然后將所有 storyboard 實例替換為FixedTextView

注意:您將丟失在情節提要中創建的所有屬性。 這可能會產生嚴重的影響(例如委托設置、大小等)

更新的解決方案:更新到Xcode 11.2.1 它適用於我的 iOS 11、12 或 13 個設備。

請參閱蘋果的文檔此更新修復了一個可能導致使用 UITextView 的應用程序崩潰的關鍵問題。

舊解決方案:https://developer.apple.com/download/more/下載 Xcode 11.1 修復了崩潰問題。

此外,對我來說,即使使用 Xcode 11.2,當我將 iPhone 升級到 13.2 時,也解決了崩潰問題。

11.2.1 轉基因種子解決了這個問題

(可用於發布到 App Store)

Go 到https://developer.apple.com/download/ 下載 Xcode 11.2.1 轉基因種子

發行說明確認它修復了這個錯誤:

在此處輸入圖像描述

您可以 go 從 Apple 開發人員網站下載最后一個 Xcode 測試版(11.2.1 GM)。

這里是直接鏈接

Xcode 11.2.1 轉基因種子

改進@garafajon 的答案。 對我來說,它在大多數情況下都有效。

///Substitute class for _UITextLayoutView bug
class FixedTextView: UITextView {
    required init?(coder: NSCoder) {
        if #available(iOS 13.2, *) {
            super.init(coder: coder)
        }
        else {
            super.init(frame: .zero, textContainer: nil)
            self.autoresizingMask = [.flexibleWidth, .flexibleHeight]
            self.contentMode = .scaleToFill

            self.isScrollEnabled = false   // causes expanding height

            // Auto Layout
            self.translatesAutoresizingMaskIntoConstraints = false
            self.font = UIFont(name: "HelveticaNeue", size: 18)
        }
    }
}

作為“快速”修復,您可以直接從代碼中添加UITextView ,而不是通過 IB。 至少它對我有用。 雖然從我的角度來看,最好回滾到以前的 Xcode/等待新的 Xcode。

這是 Xcode 11.2 的錯誤。 所有未安裝新版 iOS 版本 (13.2) 的設備上的子類 Textview 都會崩潰。 您可能最好不要使用該版本構建版本。

你現在可以:

  • 將 Xcode 降級到 11.1 或
  • 將您的設備升級到 iOS 13.2

我使用了一個成功的解決方法,但它很痛苦。 這是我遵循的過程:

  1. 在文本編輯器中打開 XIB
  2. 找到有問題的TextView 就我而言:
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="782-j1-88c" customClass="LCAnsiConsoleTextView">
  <rect key="frame" x="16" y="20" width="343" height="589"/>
  <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
  <fontDescription key="fontDescription" name="Menlo-Regular" family="Menlo" pointSize="12"/>
  <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
  1. 注意它的id (在我的例子中: id="782-j1-88c"
  2. 如上述答案中所述,覆蓋 class 並重新創建選項(我的是 Objective-C,抱歉):
@implementation FixedTextView

- (id) initWithCoder:(NSCoder*)coder
{
    if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){13,2,0}])
        self = [super initWithCoder:coder];
    else {
        self = [super initWithFrame:CGRectMake(16, 3, 343, 605)];
        self.editable = YES;
        self.selectable = YES;
        self.insetsLayoutMarginsFromSafeArea = YES;
        self.clipsToBounds = YES;
        self.clearsContextBeforeDrawing = YES;
        self.autoresizesSubviews = YES;
        self.contentMode = UIViewContentModeScaleToFill;
        self.scrollEnabled = YES;
        self.userInteractionEnabled = YES;
        self.multipleTouchEnabled = YES;
        self.translatesAutoresizingMaskIntoConstraints = NO;
        self.font = [UIFont fontWithName:@"Menlo-Regular" size:12.0];
    }
    return self;
}
  1. 請注意包含您的文本視圖 ID 的約束,並針對您的視圖或視圖 controller 中的其他元素 ID 重新創建這些約束。 就我而言:
- (id) initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self xibSetup];
        [self initView];
/*
        <constraint firstItem="75C-lt-YtE" firstAttribute="top" secondItem="782-j1-88c" secondAttribute="bottom" constant="8" symbolic="YES" id="8SH-5l-FAs"/>
        <constraint firstItem="782-j1-88c" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leadingMargin" id="Mve-aZ-HCe"/>
        <constraint firstItem="782-j1-88c" firstAttribute="leading" secondItem="75C-lt-YtE" secondAttribute="leading" id="dPG-u3-cCi"/>
        <constraint firstItem="782-j1-88c" firstAttribute="trailing" secondItem="iN0-l3-epB" secondAttribute="trailingMargin" id="sjT-0Q-hNj"/>
        <constraint firstItem="782-j1-88c" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" id="vic-vZ-osR"/>
*/
        [self.command.topAnchor constraintEqualToAnchor:self.console.bottomAnchor constant:8].active = YES;
        [self.console.leadingAnchor constraintEqualToAnchor:self.layoutMarginsGuide.leadingAnchor].active = YES;
        [self.console.leadingAnchor constraintEqualToAnchor:self.command.leadingAnchor].active = YES;
        [self.console.trailingAnchor constraintEqualToAnchor:self.trailingAnchor].active = YES;
        [self.console.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor].active = YES;

    }
    return self;
}

這樣做為我解決了這個問題,而不會丟失所需的功能。 幸運的是,我只有一個UITextView可以替換。 否則,這將變得站不住腳。

我遇到了同樣的問題,我剛剛將 Xcode 11.2 升級到 11.2.1,它運行良好。

升級后,我在 iOs 13 和 iOS 12 上進行了相同的測試,它工作正常。

請注意,在周六下午,Apple 終於承認了這個錯誤:

https://forums.developer.apple.com/thread/125287

在此處輸入圖像描述

不幸的是,目前還沒有關於他們何時會進行修復的建議。

沒有足夠的信譽添加評論,但我發現即使在 xcode 更新之后,我仍然遇到此崩潰。 直到我重新啟動我的電腦!

如果上述解決方案不能立即起作用,請嘗試重新啟動 xcode 和您的計算機。

這是因為 xCode 更新到 11.2 版本。 嘗試使用較舊的 xCode 版本,看看是否仍然崩潰。 蘋果還沒有解決這個問題。

我也有這個問題。 感謝您關注它。

我對包含 UIText 的任何視圖都有同樣的問題。 最終意識到這是由於 Xcode 11.2 錯誤導致的令人沮喪。

從這個線程中讀取,我所做的是從我的 Time Machine 回滾我以前的 Xcode 11.1,這比從 web 下載要快得多。 通過 Xcode 11.1 編譯應用程序項目后沒有任何崩潰。

我已經升級到 Xcode 11.2.1 並且錯誤仍然存在 我不知道它是否正在發生,因為我沒有使用 Storyboards。 每個視圖 controller 都有單獨的 xib。 有沒有人仍然遇到這個問題?

我正在使用可能已經使用 Xcode 11.2 構建的第三方外部框架

當我運行我的應用程序時,即使使用 Xcode 11.2.1,我仍然有這個問題

由於未捕獲的異常“NSInvalidUnarchiveOperationException”而終止應用程序,原因:“無法實例化名為 _UITextLayoutView 的 class,因為找不到名為 _UITextLayoutView 的 class; class 需要在源代碼中定義或從庫中鏈接(確保 class 是正確目標的一部分)

我是否應該要求供應商也用 Xcode 11.2.1 重建他們的框架?

它只發生在 iOS 12 上,到目前為止 iOS 13 上沒有崩潰

謝謝

1.問題:

Xcode 11.2 存在一個問題,如果使用 ZA3B5EBD8A1E9EBF44A172E8025A71 編譯,包含 UITextView 的 Storyboard 將導致應用在 iOS 13.2 之前的操作系統版本上崩潰

Xcode 11.2

檢查這個蘋果文檔

2.解決方法:

唯一的解決方案是將 Xcode 更新到11.2.111.3。

Xcode 11.2.1 專門發布以修復此崩潰問題。

在此處輸入圖像描述 檢查這個蘋果文檔。

三、建議:

我建議您使用最新版本的 Xcode 11.3 的 go,因為它支持為 iOS 13.3 開發應用程序,並且還有許多新功能。 檢查這個蘋果文檔

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

DEAD_CODE_STRIPPING = NO

在項目的構建設置中修復它。

由於_UIScrollerImpContainerView我有類似的問題

*** 由於未捕獲的異常“NSInvalidUnarchiveOperationException”而終止應用程序,原因:“無法實例化名為 _UIScrollerImpContainerView 的 class,因為找不到名為 _UIScrollerImpContainerView 的 class; class 需要在源代碼中定義或從庫中鏈接(確保 class 是正確目標的一部分)'

它出現在 Xcode 11.1 和 11.2.1 AppDelegate文件中的executeWorkaround修復在我的情況下不起作用

我發布在https://forums.developer.apple.com/message/392778#392778

此問題已在 Xcode 版本 11.2.1 中修復,並在發行說明中指出:

此更新修復了一個可能導致使用 UITextView 的應用程序崩潰的關鍵問題

Xcode 發行說明截圖

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

iOS 13.2 的手機不會出現這種情況。 這不是一個真正的解決方案,但它是一個快速修復

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM