webView如何在NSSearchPathForDirectoriesInDomains中显示ppt

时间:2016-01-14 09:30:05

标签: ios objective-c webview powerpoint cache-control

这是我的代码:

//1.Create caches

NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
self.filePath = [caches stringByAppendingPathComponent:@"xsb.ppt"];

DLog(@"%@",self.filePath);

//2.Create file manager

NSFileManager *fileManager = [NSFileManager defaultManager];

//create file
[fileManager createFileAtPath:self.filePath contents:nil attributes:nil];


//Use webView open ppt

NSURL *url = [[NSURL alloc] initFileURLWithPath:self.filePath];
self.request = [NSURLRequest requestWithURL:url];
[self.PPTWebView loadRequest:self.request];

webView错误:

  

cuoweuError Domain = WebKitErrorDomain Code = 102

谁能告诉我为什么?

1 个答案:

答案 0 :(得分:0)

删除

[fileManager createFileAtPath:self.filePath contents:nil attributes:nil];

否则文件将被覆盖。

如果您想确保webview正确处理powerpoint文件,您可以尝试将.ppt文件添加到项目中,然后像这样打开它:

NSString * pathToPowerPointFile = [[NSBundle mainBundle]
                        pathForResource:@"xsb"
                        ofType:@"ppt"];

[self.PPTWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:pathToPowerPointFile]]];