首页 > 解决方案 > NSAttributedString - 线程 1:在 iOS 14 上设置属性文本时的 EXC_BREAKPOINT(代码 = EXC_I386_BPT,子代码 = 0x0) -

问题描述

我有一些奇怪的问题。在我的 Macbook M1 上,当我构建我的项目时,everythink 在物理 iPhone XS 14.4 和 8 14.0.1 上运行良好,也在 iOS 14+ 的模拟器上运行良好。但是,当我使用比 14.0 更旧的 iOS 运行任何模拟器时,我的应用程序在设置属性文本时崩溃。这是我的代码:


        guard let input = input else { return nil }

        guard let data = input.data(using: String.Encoding.unicode, allowLossyConversion: true) else { return nil  }


        if let string = try? NSAttributedString(data: data, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html], documentAttributes: nil).string
        {
            //Set color and font
            let myAttribute = [ NSAttributedString.Key.foregroundColor: UIColor.white , NSAttributedString.Key.font: UIFont.systemFont(ofSize: 17.0)  ]
            let myAttrString = NSAttributedString(string: string, attributes: myAttribute)
            return myAttrString
        }

        return nil
    }

崩溃在这一行:

        if let string = try? NSAttributedString(data: data, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html], documentAttributes: nil).string

对于NSAttributedString ,我收到错误Thread 1: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0) 我尝试在 Macbook Intel 上运行我的应用程序,并且在 iOS 14.0 之前的模拟器上一切正常。所以这对我来说很奇怪。我是否应该将应用程序扔到 App Store 上,因为故障仅在于模拟器,或者用户可能有问题?我尝试了互联网上的各种解决方案,我更改了 NSAttributedString 修改,但应用程序总是在同一个地方崩溃。

标签: iosswiftnsattributedstringsimulator

解决方案


推荐阅读