OGeek|极客世界-中国程序员成长平台

标题: ios - 在 Objective c 中解析 RTF [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:49
标题: ios - 在 Objective c 中解析 RTF

我想在Objective c中解析RTF文件。是否可以解析它?如果可能的话,我怎样才能将它用于 IOS。我想要所有的文本和格式。 为此,我尝试了多种方式来获取文本和格式,我使用了 UIWEBVIEW,但它不返回任何文本字符串

NSURL *imgPath = [[NSBundle mainBundle] URLForResource"test" withExtension"rtf"];
NSData *data = [NSData dataWithContentsOfURL:imgPath];
[webView loadData:data MIMEType"text/rtf" textEncodingName"utf-8" baseURL:[NSURL URLWithString"/"]];
 NSString *html = [webView stringByEvaluatingJavaScriptFromString: @"document.body.innerHTML"];

这里 html 返回 nil 值。 谢谢



Best Answer-推荐答案


好的,这个问题已经很老了,但万一有人偶然发现这个问题:

html 为 nil,因为 webView 未完成加载。在 UIWebViewDelegate 中获取 html:

- (void)webViewDidFinishLoadUIWebView *)webView
{
    NSString *html = [webView stringByEvaluatingJavaScriptFromString: @"document.body.innerHTML"];

    NSLog(@"Html: %@",html);

}

您将获得所需的 html。

关于ios - 在 Objective c 中解析 RTF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17148146/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4