3
ドキュメントディレクトリにダウンロードされた.zipファイルを解凍しました。しかし、私はそれらについての質問しか見つけず、私は質問に合った適切な答えを得られませんでした。ダウンロードしたファイルをドキュメントディレクトリに解凍する方法
誰もが "MiniZip"という名前のAPIファイルをダウンロードしてそれを利用するよう提案しています。その大量のコードとその多くのコードは私のために必要ではありません。だから、もし私がファイルを解凍してそれを利用するコードを少し少なくすれば、私にとっては素晴らしいことになるでしょう。それは保存されたとおりにURLから正確にダウンロードされていますが、ドキュメントディレクトリで解凍してそれを使用する方法が得られません。私はいくつかのサンプルコードを与えたり、私に助言して助けてください。
次のコードは、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];
}
こんにちはAltealice、私もminizipで試してみましたが、私に何の結果も与えていません。あなたは私にそれを克服するための他の方法を提案してもらえますか? – raj
私のチームメイトはMiniZipを使用していましたが、私たちのプロジェクトでうまくいきました。私は彼がそれをどのように使用したかの正確な内容を知らない。たぶんあなたはいくつかのドキュメントを読んでみるべきです。 – Altealice
ちょっと今MiniZipが私のために働いてくれました...ありがとうalottt .......... – raj