【问题标题】:UIWebview load ppt and doc crash appUIWebview 加载 ppt 和 doc 崩溃应用
【发布时间】:2014-07-10 12:50:46
【问题描述】:

我需要在UIWebView 中加载doc 和ppt 文件。 我在一个控制器中有 2 个不同的 UIWebView

[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"doc" ofType:@"doc"]]]];
[self.webview1 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"ppt" ofType:@"ppt"]]]];

这会使应用程序崩溃:

OfficeImport`WrdEshBackground::takeClientData(WrdEshClientData*):
0x34c4fe3c:  str.w  r1, [r0, #224] //on this line

但是如果我加载相同格式的文件:

[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"ppt" ofType:@"ppt"]]]];
[self.webview1 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"ppt" ofType:@"ppt"]]]];

效果很好。

如果我在UIWebView 完成加载第一个请求时等待,然后从第二个开始它运行良好。 但是我需要在 tableView 中加载很多文件。 UITableViewCel 将包含加载此文件的 UIWebView

【问题讨论】:

    标签: ios objective-c uitableview uiwebview


    【解决方案1】:

    我会建议一种我曾经使用具有 MIME 类型的 NSData 对象将数据显示到 webView 中的方法,我已将我的文件转换为 NSData 对象并显示为

    if ([docType isEqualToString:@"pdf"]) {
        [webView loadData:documentDataObject MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
    } else if ([docType isEqualToString:@"doc"]) {
        [webView loadData:documentDataObject MIMEType:@"application/msword" textEncodingName:@"utf-8" baseURL:nil];
    } else if ([docType isEqualToString:@"docx"]) {
        [webView loadData:documentDataObject MIMEType:@"application/vnd.openxmlformats-officedocument.wordprocessingml.document" textEncodingName:@"utf-8" baseURL:nil];
    } else if ([docType isEqualToString:@"jpg"]) {
        [webView loadData:documentDataObject MIMEType:@"image/jpeg" textEncodingName:@"utf-8" baseURL:nil];
    } else if ([docType isEqualToString:@"png"]) {
        [webView loadData:documentDataObject MIMEType:@"image/png" textEncodingName:@"utf-8" baseURL:nil];
    }
    

    【讨论】:

    • 我尝试了您的代码,但没有帮助。 NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"doc" ofType:@"doc"]; NSData *myData = [NSData dataWithContentsOfFile:pdfPath]; [self.webview loadData:myData MIMEType:@"application/msword" textEncodingName:@"utf-8" baseURL:nil]; [self.webview1 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"ppt" ofType:@"ppt"]]]]; 这个错误OfficeImport`WrdEshReader::readClientAnchor(EshContentBase&, EshHeader const&): 0x34bc79b8: str.w r4, [r0, #348]
    • 我猜你的doc文件有问题,换个文件试试
    • doc文件没有问题,如果我尝试在webview中加载它,它工作得很好,但是如果不同类型的文件在不同的webview中的一个线程上,它会使应用程序崩溃跨度>
    • 听起来很奇怪,你为什么不创建2个线程并分别加载它们
    猜你喜欢
    • 2011-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-27
    • 1970-01-01
    • 2012-06-16
    相关资源
    最近更新 更多