title: How to check the PDF size before uploading in iOS?
body: <p>I have a requirement of uploading PDF file which is not more than 2 MB. Right now I am using the <code>UIDocumentPickerViewController</code> 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 <code>NSByteCountFormatter</code>. The code is given below:</p>
  <pre><code>NSData *fileData = [NSData dataWithContentsOfURL:url];
  NSLog(@&quot;Byte Length%@&quot;, [[NSByteCountFormatter new] stringFromByteCount:fileData.length]);
  NSString *twoMB = [[NSByteCountFormatter new] stringFromByteCount:fileData.length];
  NSString *allowedmem = @&quot;2 MB&quot;;
  if (twoMB &gt; allowedmem) {
      NSLog(@&quot;Greater than 2 MB&quot;);
  } else {
      ViewMyPDFViewController *webview = [[ViewMyPDFViewController alloc]init];
      webview.productURL = url;
      [self presentViewController:webview animated:YES completion:nil];
  }
  </code></pre>
  <p>I have tried this code but it is not working well in the <code>if</code> condition. Please tell what I am doing wrong. How do I check whether it is greater than 2 MB?</p>