gpt4 book ai didi

html - 在 NSAttributedString 中转换 html 数据的时间太长。有任何想法吗?

转载 作者:行者123 更新时间:2023-12-03 17:09:05 27 4
gpt4 key购买 nike

我正在为 macOS 开发 Objective-C 应用程序。在某些情况下,我需要使用以下代码将 html 数据转换为富文本:

NSDictionary *htmlAttrs = nil;
NSMutableAttributedString *rtfAttributedString = [[NSMutableAttributedString alloc] initWithHTML:data documentAttributes:&htmlAttrs];

问题是,有时,转换简单电子邮件的 html 正文可能需要长达 40 秒的时间,因此这个解决方案对我来说是 Not Acceptable 。我知道在堆栈溢出上还有其他类似的问题,但我想让您注意到一件奇怪的事情:在转换过程结束时,日志中会出现这样的行:

Task <A8B047AC-DABA-4259-AAF7-E2C23C84A2F1>.<0> HTTP load failed (error code: -999 [1:89])

这让我认为 NSAttributedString 可能正在尝试解析一些可能不存在的 http 链接,因此它会等待超时(40 秒超出了转换的正常持续时间,因此这可能是真的)。如果这是真的,那么可能有某种方式告诉 NSAttributedString,通过其他具有更多选项的类似方法,例如不解析链接。当然,我可能完全错了。任何帮助是极大的赞赏。谢谢

最佳答案

我还没有机会尝试此操作,但如果您使用 initWithHTML:options:documentAttributes: 版本的初始化程序,则可以使用 Timeout 选项。

NSDictionary *htmlAttrs = nil;          
NSDictionary *options = @{ NSTimeoutDocumentOption: @(0.5) };
NSMutableAttributedString *rtfAttributedString = [[NSMutableAttributedString alloc] initWithHTML:htmlData options:options documentAttributes:&htmlAttrs];

该值应该是以秒为单位的超时。

关于html - 在 NSAttributedString 中转换 html 数据的时间太长。有任何想法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53877795/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com