NSData在从Pdf转换时被篡改

时间:2017-06-01 10:05:06

标签: ios objective-c pdf nsdata

我正在尝试从目标C中的iPhone上的iClouds上传pdf。以下是我的代码,它会在点击时触发。

UIDocumentPickerViewController *doc = [[UIDocumentPickerViewController alloc]initWithDocumentTypes:@[@"public.composite-content"] inMode:UIDocumentPickerModeImport];
doc.delegate = (id)self;
doc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:doc animated:YES completion:nil];//getting the path of the file selected through  didPickDocumentAtURL
NSString *path = [url path];//converting in to data in two different ways but getting truncated nsdata
NSData *data3 = [[NSFileManager defaultManager] contentsAtPath:path];//Truncating
NSData *data1 = [NSData dataWithContentsOfFile:path];//Truncating Both data3 and data1 are getting truncated after 32767 characters.

问题:

  1. 这是将.pdf导入NSData吗?
  2. 的正确格式
  3. NSData是否有限制? (我问这个是因为它在32767个字符后完全被截断)

1 个答案:

答案 0 :(得分:0)

我通过调用UIDocumentPickerViewController的委托方法

解决了这个问题
  - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url{
                if (controller.documentPickerMode== UIDocumentPickerModeImport) {
                      //taking the path of the file selected
                       NSString *path = [url path];
                      //converting to NSData
                        NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
                       //converting to base64 string
                        base64String = [data base64EncodedStringWithOptions:kNilOptions];

                 }
     }