Created
November 10, 2015 20:25
-
-
Save eddieespinal/70a31a0dbc788db0bcda to your computer and use it in GitHub Desktop.
Revisions
-
eddieespinal created this gist
Nov 10, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ **Use this function below to check whether file exists at specified url** +(void)checkWhetherFileExistsIn:(NSURL *)fileUrl Completion:(void (^)(BOOL success, NSString *fileSize ))completion { //MAKING A HEAD REQUEST NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:fileUrl]; request.HTTPMethod = @"HEAD"; request.timeoutInterval = 3; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; if (connectionError == nil) { if ((long)[httpResponse statusCode] == 200) { //FILE EXISTS NSDictionary *dic = httpResponse.allHeaderFields; NSLog(@"Response 1 %@",[dic valueForKey:@"Content-Length"]); completion(TRUE,[dic valueForKey:@"Content-Length"]); } else { //FILE DOESNT EXIST NSLog(@"Response 2"); completion(FALSE,@""); } } else { NSLog(@"Response 3"); completion(FALSE,@""); } }]; }