考慮下面的代碼:ASIHTTPRequest setDownloadDestinationPath不寫入文件
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]);
返回如下:
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)
將有問題的URL給我發送QuickTime影片(我使用Ruby的send_data File.read(「#{file_path} .MOV」),:disposition =>'inline',:type =>「video/quicktime」)。
如您所見,目錄中沒有文件!幫幫我!
另外只是要注意,我試着用服務器的直接文件(http://192.168.2.71:3000/fake_recordings/encounters/2/complaint.MOV),而不需要一個控制器,這有相同的問題。即使我可以在兩種情況下都使用我的網絡瀏覽器正確打開文件。 – mattvv 2011-03-31 01:44:23
嘗試添加失敗回調並查看它是否被調用? – Nevin 2011-03-31 01:54:29
有效的點,我做到了,並得到這個: 2011-03-30 19:01:01.957 VideoCapture [246:707]錯誤:無法將文件從'/ private/var/mobile/Applications/AE4B3091-3726- 4FAE-B861-C4AE3616E743/tmp/6A81D988-74EF-4085-AB1F-8EFF11008736-246-0000000F08A0C88D'至'/var/mobile/Applications/AE4B3091-3726-4FAE-B861-C4AE3616E743/Documents/complaint.MOV' – mattvv 2011-03-31 02:01:27