我有一个应用程序,用户可以浏览他的保管箱帐户的文件。如果他选择一个文件,应用程序首先将其本地下载到文档目录中,然后使用QLPreviewController显示它的预览。除pdf文档外,它工作正常。它不是显示pdf,而只是一个白色的屏幕。这是代码:
- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
UINavigationController *controller = self.navigationController;
DBMetadata *file = [self.currentData.contents objectAtIndex: [indexPath row]];
if( file.isDirectory ) {
//get name of new path
NSString *path = [NSString stringWithFormat: @"%@%@/", self.currentData.path, file.filename];
SubLevelViewController *slController = [[SubLevelViewController alloc] initWithStyle:UITableViewStylePlain];
slController.dirPath = path;
[controller pushViewController: slController animated: YES];
}
else {
//save file into documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
currentFilePath = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithString: file.filename]];
NSString *dbPath = [NSString stringWithFormat: @"%@%@/", self.currentData.path, file.filename];
[self.restClient loadFile:dbPath intoPath:currentFilePath];
}
}
//rest client delegate methods
- (void)restClient:(DBRestClient *)client loadedFile:(NSString *)localPath
contentType:(NSString *)contentType metadata:(DBMetadata *)metadata {
NSLog(@"File loaded into path: %@", localPath);
//load the file preview and push onto the nav controller
QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.dataSource = self;
previewController.currentPreviewItemIndex = 0;
[[self navigationController] pushViewController:previewController animated:YES];
}
- (id)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
NSURL *fileURL = nil;
fileURL = [NSURL fileURLWithPath:currentFilePath];
return fileURL;
}