HTML 属性字符串在 Mac Catalyst 中不起作用,但在 iPhone 和 iPad 上运行良好。 HTML 字符串代码如下。
var htmlToAttributedString: NSAttributedString? {
guard let data = data(using: .utf8) else { return NSAttributedString() }
do {
return try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding:String.Encoding.utf8.rawValue], documentAttributes: nil)
} catch {
return NSAttributedString()
}
}
Mac Catalyst 中的错误是
连接到名为 com.apple.textkit.nsattributedstringagent 的 pid 17352 上的服务:在解码对消息“renderHTML:options:withReply:”的回复期间捕获异常,丢弃传入消息并调用失败 block 。
忽略异常:解码参数 1(调用的#2)时出现异常:
<NSInvocation: 0x600001802d80>
return value: {v} void
target: {@?} 0x0 (block)
argument 1: {@} 0x7fff85206780
argument 2: {@} 0x0
argument 3: {@} 0x0
Exception: value for key 'NS.objects' was of unexpected class 'NSColor'. Allowed classes are '{(
NSNull,
UIColor,
NSArray
)}'.
最佳答案
我认为这是 Mac Catalyst 的一个错误。 NSAtrribulated 字符串生成 Catalyst 不支持的 NSColor
关于swift - HTML 字符串在 MAC Catalyst 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62795786/