Consider the following code:
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://192.168.2.71:3000/ios_file?filename=complaint&folder=encounters&id=3"]];
NSString *mediaPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
mediaPath = [mediaPath stringByAppendingPathComponent:@"complaint.MOV"];
[request setDownloadDestinationPath:mediaPath];
[request startSynchronous];
NSLog(@"Got the file!");
NSURL *theURL = [NSURL URLWithString:mediaPath];
NSLog(@"Time to Play File!");
NSLog(@"Filename is %@", [theURL absoluteString]);
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[theURL absoluteString]];
if (fileExists) {
NSLog(@"THE FILE EXISTS ZOMG");
}
// Create file manager
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
// Point to Document directory
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
// Write out the contents of home directory to console
NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
Returns the following:
2011-03-30 18:29:46.107 VideoCapture[158:707] Get recording from server
2011-03-30 18:29:46.976 VideoCapture[158:707] Got the file!
2011-03-30 18:29:46.978 VideoCapture[158:707] Time to Play File!
2011-03-30 18:29:46.980 VideoCapture[158:707] Filename is /var/mobile/Applications/AE4B3091-3726-4FAE-B861-C4AE3616E743/Documents/complaint.MOV
2011-03-30 18:29:46.986 VideoCapture[158:707] Documents directory: (null)
Going to the URL in question sends me a quicktime movie (I’m using Ruby’s send_data File.read(“#{file_path}.MOV”), :disposition => ‘inline’, :type => “video/quicktime”).
As you can see, there are no files in the directory! Help!
Under iOS
NSHomeDirectory()and the appended path isn’t the proper way to get to the Document directory and may be what’s hanging you up. Instead use something along these lines: