swift - HTML 字符串在 MAC Catalyst 中不起作用
问题描述
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:”的回复进行解码时捕获异常,丢弃传入消息并调用失败块。
忽略的异常:解码参数 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 的错误。生成 NSColor 的 NSAtributed 字符串在 Catalyst 中不受支持