Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从Xcode 11.1升级到Xcode 11.2后,由于_UITextLayoutView,应用程序崩溃_Ios_Swift_Xcode_Uitextview_Xcode11.2 - Fatal编程技术网

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

Ios 从Xcode 11.1升级到Xcode 11.2后,由于_UITextLayoutView,应用程序崩溃,ios,swift,xcode,uitextview,xcode11.2,Ios,Swift,Xcode,Uitextview,Xcode11.2,从Xcode 11.1升级到Xcode 11.2后,我的应用程序崩溃: ***由于未捕获的异常“NSInvalidUnarchiveOperationException”而终止应用程序,原因:“无法实例化名为_-UITextLayoutView的类,因为未找到名为_-UITextLayoutView的类;该类需要在源代码中定义或从库中链接(确保该类是正确目标的一部分)' 为什么会这样?如何防止此崩溃?作为“快速”修复,您可以直接从代码中添加UITextView,而不是通过IB。至少它对我有效。虽

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

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


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

作为“快速”修复,您可以直接从代码中添加
UITextView
,而不是通过IB。至少它对我有效。虽然从我的观点来看,最好回滚到以前的Xcode/等待新的Xcode。

更新:修复 更新的解决方案: 更新至Xcode 11.2.1。它可以在iOS 11、12或13设备上运行

指 此更新修复了一个可能导致使用UITextView的应用程序崩溃的关键问题

旧的解决方案: 从下载的Xcode 11.1 从11.2切换回11.1修复了碰撞

此外,对于我来说,即使使用Xcode 11.2,当我将iPhone升级到13.2时,也修复了崩溃。

更快的修复方法:

///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)
        }
    }
}
将此代码添加到某个位置,然后将所有情节提要实例替换为
FixedTextView


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

这是Xcode 11.2的一个bug。子类文本视图在所有未安装新ESET iOS版本(13.2)的设备上崩溃。您可能最好不要使用该版本构建发行版

您现在可以:

  • 将Xcode降级至11.1或
  • 将您的设备升级到iOS 13.2

改进@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)
        }
    }
}

祝贺

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

解决办法

@Mojtaba Hosseini我提出的解决方案来自于StackOverflow的帮助和我的开发伙伴们的参与。你、我和所有其他开发者都已经知道,当苹果发布新版本时,这个问题将消失

但除了一切

Apple Review明确接受了上述解决方案,因为根本不涉及私有API。这种方法非常类似于创建属性,如

@界面UITextView(布局)

UITextView+Layout.h

所以,当您创建属性时,您直接使用APPLE私有组件,并根据您的需要对其进行重新模块化

简单的例子是AMFNetworking类

- (void)setImageWithURL:(NSURL *)url {
    [self setImageWithURL:url placeholderImage:nil];
}
希望我对指控了结

下面的答案只是我这边的一些帮助,使开发人员能够继续开发,因为我们最初建议开发人员回滚Xcode。再次下载8gbxcode是一种糟糕的做法,因为我们都知道新版本的Xcode即将发布

虽然它在Xcode 11.2.1中已修复,但我为Xcode 11.2提供了一个解决方案,您可以通过该解决方案摆脱此崩溃:

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

解决方案

转到构建设置搜索“死代码剥离”,并将其设置为否

DEAD_CODE_STRIPPING = NO
然后

创建文件UITextViewWorkaround

UITextViewWorkaround.h

    #import <Foundation/Foundation.h>


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

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

我已将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
中的
didfishlaunchingwithoptions
末尾调用它


谢谢@Aftab

问题已在Xcode 11.2.1中修复

编辑:随着修复程序的发布,您应该切换到该Xcode版本,并注释掉该解决方案。正如Mojtaba Hosseini在回答中提到的:

。。。这最后两个令人毛骨悚然的解决方案正在使用Apple私有API,将被Apple review拒绝

在苹果发布补丁之前,这是一个很好的解决方案,可以继续开发和测试


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

故事板文件无需更改

编辑了my 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
           }
        }
    }
}
在代表中,调用“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()
}

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

  • 在文本编辑器中打开XIB
  • 查找有问题的
    TextView
    。就我而言:
  • 
    
  • 注意它的
    id
    (在我的例子中:
    id=“782-j1-88c”
  • 覆盖上面答案中提到的类并重新创建选项(我的是Objective-C,抱歉):
  • @implementation-FixedTextView
    -(id)initWithCoder:(NSCoder*)编码器
    {
    if([[NSProcessInfo processInfo]IsoperatingSystemMatleASTVersion:(NSOperatingSystemVersion){13,2,0}])
    self=[super initWithCoder:coder];
    否则{
    self=[superinitwithframe:CGRectMake(16,3343605)];
    self.editable=是;
    self.selective=是;
    self.insetsLayoutMarginsFromSafeArea=是;
    self.clipstobunds=是;
    self.clearsContextBeforeDrawing=是;
    self.autoresizesSubviews=是;
    self.contentMode=UIViewContentModeScaleToFill;
    self.scrollEnabled=是;
    self.userInteractionEnabled=是;
    自多重触控=
    
    //******************************************************************
    // 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
               }
            }
        }
    }
    
    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()
    }