【发布时间】:2016-09-08 10:13:44
【问题描述】:
我有一个 PDF 文件,从 iCloud 获取,并希望将该 PDF 文件转换为二进制文件。
代码片段:
-(IBAction)iCloudDriveFullFolder:(id)sender
{
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.data"]
inMode:UIDocumentPickerModeImport];
documentPicker.delegate = self;
documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:documentPicker animated:YES completion:nil];
}
#pragma mark - iCloud files
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
if (controller.documentPickerMode == UIDocumentPickerModeImport)
{
NSString *alertMessage = [NSString stringWithFormat:@"Successfully imported %@", [url lastPathComponent]];
NSLog(@"alertMessage %@",alertMessage);
}
使用此代码,我从 iCloud 获得了 PDF 文件。 alertMessage 得到了那个 PDF 文件。我怎样才能转换成二进制。帮我。提前谢谢。
【问题讨论】:
-
您可以使用以下代码 NSData *data = [NSData dataWithContentsOfFile:strURL];
-
我如何使用此代码。将 alertMessage 字符串传递给 strURL 。但我得到了空值。
-
这里需要提供PDF的路径url。导入 PDF 后,您必须将其保存在某个位置,使用该路径。我从来没有导入过这样的东西,但是如果你有路径,那么你可以使用该方法获取二进制数据
-
NSString *alertMessage = [NSString stringWithFormat:@"成功导入%@", [url lastPathComponent]]; “alertMessage”得到了pdf文件。我该如何转换它
标签: ios objective-c