NSAttributedString from html is not loading resources
I'm trying to move from
NSAttributedString.init(data:options:)
to NSAttributedString.fromHTML(_:options)
, which is asynchronous.
It's working fine, except that the CSS inside the html doesn't load my custom fonts. The previous version loaded then without any problem. I can share the code, but it's very app specific.
This is the CSS I want working correctly.
I just want to know if there's any additional config I need to get the resources loaded.
This code works fine, but hangs if too there are too many calls at the same time:
And this code is the one that works, but doesn't load my fonts:
2 Replies
According the the docs, I can only set the
DocumentReadingOptionKey
for baseURL
on macOS, not on iOS.
My guess is that is why it fails.
@Community Coach Does anyone know about this html conversion?
@Coach I understand if it's too early to ping, but I need some helpI'm not sure that using css to inject fonts not installed on the device is an intended use-case of NSAttributedString
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/AttributedStrings/Tasks/CreatingAttributedStrings.html#//apple_ref/doc/uid/20000714-BBCCGGCC
The methods translate HTML as well as possible into structures of the Cocoa text system, but the Application Kit does not provide complete, true rendering of arbitrary HTML
Creating Attributed Strings in Cocoa
Explains how to use attributed strings, which manage attributes of character strings or individual characters.