title: Detect file type from NSURL
body: <p>I have NSURL variable that contains different web links.I want to detect the type of the file that contains this link( if it contains any).
  In example this is pdf file: <a href="https://vk.com/doc-105831417_445462965" rel="nofollow noreferrer">https://vk.com/doc-105831417_445462965</a>
  How can I detect that this is PDF File or other type of file(ex. ZIP, doc) in code?
  I have this code, but it's only working for files on the hardware:</p>
  
  <pre><code>CFStringRef fileExtension = (__bridge CFStringRef) [filePath pathExtension];
  CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
  
  
  if([self ifZip:filePath]){
  
      return ACFileTypeZIP;
  
  }
  
  if (UTTypeConformsTo(fileUTI, kUTTypeMovie)){
  
      return ACFileTypeZIP;
  
  }else if (UTTypeConformsTo(fileUTI, kUTTypePDF)){
  
      return ACFileTypeDocument;
  
  }else if (UTTypeConformsTo(fileUTI, kUTTypeImage)){
  
      return ACFileTypeImage;
  
  }else if (UTTypeConformsTo(fileUTI, kUTTypeAudio)){
  
      return ACFileTypeAudio;
  
  }
  
  CFRelease(fileUTI);
  </code></pre>
  
  <p>Note ACFileType is my enum of types.ifZip is my method for detecting zip files:</p>
  
  <pre><code>-(BOOL)ifZip:(NSString*)path{
  
  
  NSFileHandle *fh = [NSFileHandle fileHandleForReadingAtPath:path];
  NSData *data = [fh readDataOfLength:4];
  if ([data length] == 4) {
      const char *bytes = [data bytes];
      if (bytes[0] == 'P' &amp;&amp; bytes[1] == 'K' &amp;&amp; bytes[2] == 3 &amp;&amp; bytes[3] == 4) {
          return YES;
      }
  }
  
  return NO;}
  </code></pre>