I am developing an Objective-C application for macOS. In some cases I need to convert html data to rich text using this code:
NSDictionary *htmlAttrs = nil;
NSMutableAttributedString *rtfAttributedString = [[NSMutableAttributedString alloc] initWithHTML:data documentAttributes:&htmlAttrs];
The problem is that some times, for converting the html body of a simple email, it can take up to 40 seconds, and thus this solution is not acceptable for me. I am aware that there are other questions similar to this on stack overflow, but I would like to make you notice a strange thing: at the end of the conversion process a line like this is presented in the log:
Task <A8B047AC-DABA-4259-AAF7-E2C23C84A2F1>.<0> HTTP load failed (error code: -999 [1:89])
This makes me think that NSAttributedString is probably trying to resolve some http links which are probably inexistent, so it kind of waits for a timeout (40 seconds is beyond the normal duration of the conversion so this could likely be true). If this is true, then there could be some way of telling to NSAttributedString, via the other similar methods that take more options, to not resolve links for example. Of course, I could be totally wrong. Any help is greatly appreciated. Thanks
I haven't had a chance to try this but if you use the initWithHTML:options:documentAttributes:
version of the initializer, you can use the Timeout
option.
NSDictionary *htmlAttrs = nil;
NSDictionary *options = @{ NSTimeoutDocumentOption: @(0.5) };
NSMutableAttributedString *rtfAttributedString = [[NSMutableAttributedString alloc] initWithHTML:htmlData options:options documentAttributes:&htmlAttrs];
The value should be a timeout in seconds.