Use NSURLSession and NSURLConnection to obtain the MIMEType and nsurl of the file.
Both NSURLSession and NSURLConnection are Apple's built-in classes for network requests. NSURLSession was launched after iOS 7.0 to replace NSURLConnection. The following describes how to obtain the file MIMEType using these two classes.
1 # pragma mark get the mimeType 2 of the file // NSURLSession Version 3-(void) getMIMEType {4 // use NSBundle to obtain the file path in the project. 5 NSString * filePath = [[NSBundle mainBundle] pathForResource: @ "a" ofType: @ "png"]; 6 // create NSURL object 7 NSURL * fileUrl = [NSURL fileURLWithPath: filePath]; 8 // CREATE request 9 NSURLRequest * request = [NSURLRequest requestWithURL: fileUrl]; 10 // create NSURLSession Singleton 11 NSURLSession * session = [NSURLSession sharedSession]; 12 // create a dataTask request data 13 NSURLSessionDataTask * dataTask = [session dataTaskWithRequest: request completionHandler: ^ (NSData * data, NSURLResponse * response, NSError * error) {14 // response. MIMEType is the MIMEType15 NSLog (@ "% @", response. MIMEType); 16}]; 17 // session tasks are suspended by default. You need to manually enable 18 [dataTask resume]; 19} 20 // NSURLConnection version 21-(void) getMIMEType1 {22 // use NSBundle to obtain the file path 23 NSString * filePath = [[NSBundle mainBundle] pathForResource: @ "a" ofType: @ "png"]; 24 // create NSURL object 25 NSURL * fileUrl = [NSURL fileURLWithPath: filePath]; 26 // CREATE request 27 NSURLRequest * request = [NSURLRequest requestWithURL: fileUrl]; 28 NSURLResponse * response = nil; 29 // synchronous request 30 [NSURLConnection sendSynchronousRequest: request returningResponse: & response error: nil]; 31 // response. MIMEType is the MIMEType32 NSLog (@ "% @", response. MIMEType); 33}