lif*_*son 2 iphone zip objective-c nsurlconnection
目前使用SSZipArchive方法下载zip文件并在Documents目录文件夹中解压缩.我正在从URL下载zip文件名,目前不知道文件名,因为每次有任何更新时它都会更改.如何在收到数据时检索文件名?
- (void)viewDidLoad {
fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
directoryPath = [paths objectAtIndex:0];
filePath = [NSString stringWithFormat:@"%@/ZipFiles.zip", directoryPath];
NSURL *url=[NSURL URLWithString:@"http://www.abc.com/test/test.cfc?id=123"];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
[fileManager createFileAtPath:filePath contents:urlData attributes:nil];
[SSZipArchive unzipFileAtPath:filePath toDestination:directoryPath];
NSString *responseString = [[NSString alloc] initWithData:urlData encoding:NSASCIIStringEncoding];
///***Answer to my own question for future needs****//
NSString *fileName = [response suggestedFilename];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1855 次 |
| 最近记录: |