Reputation: 105
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:
NSData
?NSData
? (I am asking this because it's getting truncated exactly after 32767 characters)Upvotes: 0
Views: 271
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