I have a requirement of uploading PDF file which is not more than 2 MB. Right now I am using the UIDocumentPickerViewController
to browse the PDF files. Is there any way to check whether the PDF's size is larger than 2 MB? I am able to get the size using NSByteCountFormatter
. The code is given below:
NSData *fileData = [NSData dataWithContentsOfURL:url];
NSLog(@"Byte Length%@", [[NSByteCountFormatter new] stringFromByteCount:fileData.length]);
NSString *twoMB = [[NSByteCountFormatter new] stringFromByteCount:fileData.length];
NSString *allowedmem = @"2 MB";
if (twoMB > allowedmem) {
NSLog(@"Greater than 2 MB");
} else {
ViewMyPDFViewController *webview = [[ViewMyPDFViewController alloc]init];
webview.productURL = url;
[self presentViewController:webview animated:YES completion:nil];
}
I have tried this code but it is not working well in the if
condition. Please tell what I am doing wrong. How do I check whether it is greater than 2 MB?