从Xcode 11.1升级到Xcode 11.2后,由于_UITextLayoutView,应用程序崩溃

Sud*_*ula 336 xcode uitextview ios swift xcode11.2

从Xcode 11.1升级到Xcode 11.2之后,我的应用崩溃了:

***由于未捕获的异常'NSInvalidUnarchiveOperationException'而终止应用程序,原因:'无法实例化名为_UITextLayoutView的类,因为未找到名为_UITextLayoutView的类;该类需要在源代码中定义或从库中链接(确保该类是正确目标的一部分)'

为什么会这样呢?如何防止此崩溃?

Moj*_*ini 213

更新:固定!

唯一的解决方案是更新

错误已在Xcode 11.2.1中修复。因此,您可以从此处下载并使用它。

包含UITextView的情节提要板将不再导致应用程序在iOS 13.2,tvOS 13.2或macOS 10.15.2之前的操作系统版本上崩溃。(56808566,56873523)


Apple已于2019年11月5日弃用Xcode 11.2

如果您曾经尝试将使用Xcode 11.2构建的应用提交到AppStore,则将被拒绝:

App Store Connect操作警告

警告ITMS-90703:“不建议使用的Xcode构建。由于已解决的应用程序存档问题,我们已于2019年11月5日弃用了Xcode 11.2。下载Xcode 11.2.1或更高版本,重建您的应用并重新提交。”

因此,使用Xcode 11.2完成的所有变通办法都没有用


这是Xcode 11.2的错误,已在Xcode 11.2.1中修复。

解决方案

回滚到之前的Xcode 发布版本从:回滚是不是一种选择了和AppStore的将拒绝任何的Xcode构建以下11.2.1 看看这个

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版本和其他资源链接(包括发行版和Beta版)。

解决方法

这非常困难,但是可以解决。替换所有UITextView以s 故事板 S和厦门国际银行有s 纯代码版本。


请注意,错误已由Apple找到并修复。

固定

同样,该错误已由Apple Staff edford确认

确认书


对于使用iOS 13.2且无法再使用Xcode 11.1的用户:

  1. 将macOS更新到10.15.1或更高版本
  2. 安装Xcode 11.2.1或更高版本
  3. 现在应该可以在更新的设备上工作了。

对于那些拥有分镜脚本的用户:

  1. 子类 UITextView
  2. 分配给所有UITextView对象
  3. 不要忘记更新可能在子类中丢失的任何属性更改。

对于那些习惯方法混乱的人(OBJC和动态行为)

转到Objective-C@aftab muhammed khan 答案Swift适应版本的@MikRo 答案

只是不再这样做:

即使这最后两个麻烦的解决方法没有使用Apple私有API,它们也会在AppStore中被拒绝,因为Apple不会接受11.2.1下的Xcode版本的构建

再一次:

Apple已于2019年11月5日弃用Xcode 11.2

  • 请注意,您可能应该从开发设备中删除应用程序和/或清理Xcode的build文件夹(`CMD + Shift + K`) (5认同)
  • 悲伤,但是解决方案对我有用。谢谢!11.1的作品。我不建议转换为纯代码,因为我敢打赌很快就会有一个修复程序。如果您不介意:有新版本可用时,请更新此答案。如果人们开始下载11.1事件,尽管那里有一个固定的版本,那就太糟糕了:) (3认同)
  • 如何升级到v11.2.1?它没有显示在应用商店上。从开发人员门户网站下载GM种子会尝试以大约8gb的价格全部下载该应用程序! (3认同)
  • 另外,如果不建议使用,为什么Apple现在不立即在应用商店中删除11.2? (3认同)
  • 我已经有11.1,但没有用,没有升级到11.2。 (2认同)

aft*_*han 137

恭喜啦

新版本的Xcode(11.2.1)现在可用,这是摆脱此问题的最佳方法。

解决方法

@Mojtaba Hosseini我提出的解决方案来自于StackOverflow的帮助和我的同伴开发人员的参与。您,我以及此处的所有其他开发人员已经知道,当Apple宣布新版本时,此问题将消失。

但是除了一切

由于完全不涉及私有API,因此上述解决方案已被Apple Review接受。这种方法非常类似于创建属性,例如

@interface UITextView(布局)

要么

UITextView + Layout.h

因此,当您创建属性时,您将直接使用APPLE私有组件并根据您的需求或要求对它们进行重新调制。

最简单的示例是AMFNetworking类

- (void)setImageWithURL:(NSURL *)url {
    [self setImageWithURL:url placeholderImage:nil];
}
Run Code Online (Sandbox Code Playgroud)

希望我已经完成指控

下面的答案只是我方面的一些帮助,使开发人员可以继续开发,因为您最初建议开发人员回滚Xcode。再次下载8 GB Xcode是一种不好的做法,因为我们都知道即将发布新版本的Xcode。

虽然它已在Xcode 11.2.1中修复,但我得到了Xcode 11.2的一种解决方案,您可以摆脱这种崩溃:

***由于未捕获的异常'NSInvalidUnarchiveOperationException'而终止应用程序,原因:'无法实例化名为_UITextLayoutView的类,因为未找到名为_UITextLayoutView的类;该类需要在源代码中定义或从库中链接(确保该类是正确目标的一部分)'

转到“构建设置”搜索“ DEAD_CODE_STRIPPING”并将其设置为“ NO”

DEAD_CODE_STRIPPING = NO
Run Code Online (Sandbox Code Playgroud)

然后

创建文件UITextViewWorkaround

UITextViewWorkaround.h

    #import <Foundation/Foundation.h>


    @interface UITextViewWorkaround : NSObject
    + (void)executeWorkaround; 
@end
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

在应用程序委托中执行

#import "UITextViewWorkaround.h"

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

            [UITextViewWorkaround executeWorkaround];
    return yes;
    }
Run Code Online (Sandbox Code Playgroud)

编译代码,您将拥有一个正在运行的应用程序:)

  • @pradipsutariya是,当然,为什么我们不改变APPLE CLASSES的任何内容。 (5认同)
  • 仅发布Xcode 11.2.1 GM种子(测试版)。稳定版本可能会很快发布。 (5认同)
  • @Hardy_Germany我对此进行了一些测试,可以为Swift进行尝试:类UITextViewWorkaround:NSObject {类func executeWorkaround(){如果#available(iOS 13.2,*){}其他{让className =“ _UITextLayoutView” var cls = objc_getClass(className )if cls == nil {cls = objc_allocateClassPair(UIView.self,className,0)objc_registerClassPair(cls as!AnyClass)#if DEBUG print(“添加%@动态\ n”,className); #万一 } } } } (3认同)
  • 如果它对您有用,请其他人也可以尝试此解决方案 (2认同)
  • @DaveDude DEAD_CODE_STRIPPING =如果将Swift Package Manager与Xcode 11.2结合使用,则不需要 (2认同)

Har*_*any 40

该问题已在Xcode 11.2.1中修复。

编辑:现在发布了此修复程序,您应该切换到该Xcode版本并注释掉此变通办法。正如Mojtaba Hosseini在回答中提到的那样:

...这两个令人毛骨悚然的解决方法正在使用Apple私有API,将被Apple审查拒绝!

在Apple发布此修复程序之前,这是继续开发和测试的好方法。


对于Xcode 11.2,基于Aftab Muhammed Khan的想法,并在John Nimis的帮助下,我仅测试了以下代码。

情节提要文件中无需更改!

编辑了我的AppDelegate.swift文件并添加了此类

//******************************************************************
// 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
           }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

并在对“ 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()
}
Run Code Online (Sandbox Code Playgroud)


小智 34

我已将可汗的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!)
            }
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

在结束说它didFinishLaunchingWithOptionsAppDelegate

谢谢@Aftab!


gar*_*jon 22

更快的修复:

///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)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

将此代码添加到某处,然后将所有情节提要实例替换为FixedTextView

注意:您将丢失在情节提要中创建的所有属性。这可能会产生严重的影响(例如,委托人设置,人数等)


ano*_*dha 19

更新的解决方案: 更新到Xcode 11.2.1。对我来说,它可以在ios 11、12或13设备上使用。

请参阅苹果的文档

旧解决方案:https://developer.apple.com/download/more/下载了Xcode 11.1, 从11.2切换回11.1修复了崩溃。

同样,即使对于Xcode 11.2,当我将iPhone升级到13.2时,它也解决了崩溃问题。

  • 鉴于OP是在开发人员的角度进行讨论,因此升级iOS显然不是解决方案。 (6认同)
  • 这是最简单的修复-将iPhone iOS升级到13.2 (2认同)
  • Apple 确认该错误发生在 13.2 之前的 iOS 版本和 Xcode 11.2 中。 (2认同)

cra*_*aft 17

11.2.1转基因种子解决了这个问题

(它可以用于发布到App Store)

转到https://developer.apple.com/download/。下载Xcode 11.2.1 GM种子

发行说明确认它已解决此错误:

在此处输入图片说明

  • 请注意,在安装Xcode 11.2.1 GM种子之后,您可能应该从开发设备中删除该应用程序和/或清理Xcode的build文件夹(CMD + Shift + K)。 (4认同)

Aws*_*m3D 12

@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)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


Bos*_*sOz 12

您可以从Apple开发人员网站下载最新的XCode beta版本(11.2.1 GM)。

这里直接链接

在此处输入图片说明

希望有帮助


Pav*_*nov 8

作为“快速”修复,您可以UITextView直接从代码中添加,而无需通过IB。至少对我有用。尽管从我的角度来看,最好回滚到以前的Xcode /等待新的Xcode。


mar*_*cgn 6

It is a bug with Xcode 11.2. Subclassed Textviews are crashing on all devices not having the neweset iOS build (13.2) installed. You probably better not build a release with that build.

You can now:

  • 将Xcode降级为11.1或
  • 将设备升级到iOS 13.2

  • 问题是,如果崩溃发生在每个iOS小于13.2的已发布应用程序上...我恐怕要尝试... (2认同)

Eri*_*nge 6

我使用了成功的解决方法,但这很痛苦。这是我遵循的过程:

  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>
Run Code Online (Sandbox Code Playgroud)
  1. 注意它id(在我的情况:id="782-j1-88c"
  2. 按照上面的答案覆盖该类,然后重新创建选项(我的是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;
}
Run Code Online (Sandbox Code Playgroud)
  1. 请注意包括您的文本视图ID的约束,然后针对视图或视图控制器中的其他元素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;
}

Run Code Online (Sandbox Code Playgroud)

这样做对我来说解决了这个问题,而不会损失所需的功能。幸运的是我只UITextView需要更换一个。否则,这将变得站不住脚。