我有NSData
,我保存在文件目录中的文件夹中,文件扩展名为.pdf&当我尝试使用UIDocumentInteractionController
打开它时,它只向我显示文件名&类型,而不是内容。我检查了文件目录文件夹中的模拟器和放大器那里有一个.pdf文件。
//Saving NSData
+ (NSString *)createTempDocumentDirectory:(NSString *)dirName
andStoreData:(NSData *)data
withFileName:(NSString *)name
andFileExtension:(NSString *)extension
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Fetch path for document directory
NSMutableString *dirPath = (NSMutableString *)[documentsDirectory stringByAppendingPathComponent:dirName];
NSString *fileName = [NSString stringWithFormat:@"%@.%@", name, extension];
NSString *path = [dirPath stringByAppendingPathComponent:fileName];
return path;
} //Presenting contents of view
- (void)loadDocumentPreview:(NSURL *)fileURL
{
if (fileURL)
{
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[self fileURLDocumentPath:documentPath]];
self.documentInteractionController.name = @"";
[self.documentInteractionController setDelegate:self];
[self.documentInteractionController presentPreviewAnimated:YES];
}
}