Search code examples
iphoneobjective-ciosurlnsfilemanager

Identify file type from URL in an iPhone app


For an iPhone app, I am downloading files using URL:

From this type of url:: http://xxxxxxxxxxxxxxxxxxx.com/xxxxxxx//xxx/ipad.html?operation=getFile&contentId=61768b16-6b44-4d0b-bdcf-d10107d1f328

I am downloading files from server but it may be of type .pdf or .docx or .doc

Is there any way to identify file type from url?


Solution

  • In the follwing NSURLConnectionDelegate method

    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSString *mimeType = [response MIMEType]
    NString *suggestedFilename = [response suggestedFilename];
    
    }
    

    Of course it works only if you get them from server.