我搜索了解压缩在文档目录中下载的.zip文件。但我发现只有他们的问题,我没有得到任何适合我的查询的答案。
每个人都建议下载一些名为“MiniZip”的api文件并使用它。但它庞大的代码和那么多代码对我来说并不需要。所以,如果我获得更少的代码来解压缩文件并使用它,那对我来说会很棒。它完全从存储的URL下载,但我没有得到如何解压缩并在文档目录中使用它。任何人都可以通过提供一些示例代码或建议我帮助我..
以下代码是使用网址下载我的zip文件的代码。
-(IBAction)download:(id)sender{
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://some url contains .zip file"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Inform the user that the download failed.
recievedData=[[NSMutableData data ]retain];
// [recievedData writeToFile:path atomically:YES];
NSLog(@"download ");
}
else {
NSLog(@"download fail");
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[recievedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[recievedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection
didFailWithError:(NSError *)error
{
[connection release];
[recievedData release];
// inform the user
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// do something with the data
// receivedData is declared as a method instance elsewhere
NSLog(@"Succeeded! Received %d bytes of data",[recievedData length]);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path=[documentsDirectory stringByAppendingPathComponent:@"books"];
NSLog(@"value of the path is:%@",path);
[recievedData writeToFile:[path stringByAppendingPathComponent:@"file"] atomically:YES];
[connection release];
[recievedData release];
}