UseriOSDev
UseriOSDev

Reputation: 105

NSData getting trucated while converting from Pdf

I am trying to upload a pdf from iClouds in iPhone in Objective C. The following is my code which gets triggered on click.

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.

Questions:

  1. Is this correct format for importing a .pdf into NSData?
  2. Is there any limit for NSData? (I am asking this because it's getting truncated exactly after 32767 characters)

Upvotes: 0

Views: 271

Answers (1)

UseriOSDev
UseriOSDev

Reputation: 105

I solved it by calling the delegate method of 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];

                 }
     }

Upvotes: 1

Related Questions