ios - 用macHacha拼零件时解压出错

标签 ios ipad compression

好的,我有适用于 iPad 的阅读杂志的应用程序。以前的所有问题都可以正常工作。我设法提出新问题(在离开公司的其他人完成之前)并在模拟器和设备上毫无问题地运行它。

现在我在数据库中添加新一期杂志的行,并通过ZIP工具压缩所有图片和多媒体,然后通过MacHacha将它们分开(因为上传的Java类需要MacHacha的部分逐个上传)并上传到服务器上。在 App store 我下载了杂志,可以看到新一期。服务器上的新行很好,具有所有良好的参数,并且大小足以满足磁盘上的大小。

当新一期芬兰语下载时,它显示错误。我在模拟器和输出中尝试了相同的程序,当它崩溃时显示解压缩错误(0)。

我认为问题在于将零件与 MacHacha 放在一起。任何人都可以帮助或给我解决这个问题的方法。

如果有帮助,我可以上传新一期并提供链接(免费)我对你们有帮助 :)

http://www.mazzantieditori.it/applicazioni/219-nycit-italian-american-magazine.html

申请链接。在图书馆中,有几期,最后一期是新的(Giugno 2011)。

我将提供该方法的代码,该方法会给出错误的字符串:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection

{
//控制收据 è corretto e faccio partire il download if(min == 0 && [接收数据长度]

NSString *file = [[self documentsDir:1] stringByAppendingPathComponent:@"archivio.zip"];

if (max <= num && !cancelDownload) {
    self.progressBar.progress = (1.0f/num)*min;
    min = max+1;
    max += 5;

    // creo directory per l'elemento scaricato
    BOOL isDir = NO;

    if(![[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&isDir]) {
        NSError *error;
        //creo directory
        [[NSFileManager defaultManager] createDirectoryAtPath:[self documentsDir:1] withIntermediateDirectories:YES attributes:nil error:&error];
        //creo file vuoto
        [[NSFileManager defaultManager] createFileAtPath:file contents:nil attributes:nil];
    }

    NSFileHandle *handler = [NSFileHandle fileHandleForWritingAtPath:file];

    if(handler) {
        [handler seekToEndOfFile];
        [handler writeData:receivedData];
    }
    NSLog(@"Received %d bytes of data; min: %i max: %i",[receivedData length],min,max);
    [receivedData setLength:0];

    // questa è la seconda invocazione
    [self downloadArchivePart:@"verified"];
    [connection release];
    return;
}

NSFileManager *man = [[NSFileManager alloc] init];
NSDictionary *attrs = [man attributesOfItemAtPath:file error: NULL];
//UInt32 result = 
NSNumber *size = [attrs objectForKey:NSFileSize];
//int length = [receivedData length];
NSLog(@"Succeeded! Received %i bytes of data",[size intValue]);
[man release];

//1.038.090 è il numero di byte della parte più piccola dell'archivio
if([size intValue]  >= kMinPartSize) {  

    NSLog(@"prod %@",self.prodName);
    if(self.prodName == nil || [self.prodName isEqualToString:@""]) self.prodName = prodId;         

    NSError *error;
    BOOL ok = [TWZipArchive unzipFileAtPath:file toDestination:[self documentsDir:1] overwrite:YES password:nil error:&error];
    //unzipFileAtPath:file toDestination:[self documentsDir]];

    NSString *msg;
    if(ok) {
        NSLog(@"decompression successfull");
        self.progressBar.progress = 1.0f;
        NSFileManager *fm = [NSFileManager defaultManager];
        [fm removeItemAtPath:file error:&error];
        msg = @"Download completed: new issue added in libray";

        NSMutableArray *array;
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        NSString *path = [[self documentsDir:0] stringByAppendingPathComponent:@"downloaded.plist"];
        if(![[NSFileManager defaultManager] fileExistsAtPath:path]) {   
            [dict setObject:prodId forKey:@"id"];
            [dict setObject:prodName forKey:@"titolo"];
            array = [NSArray arrayWithObject:dict];
            [array writeToFile:path atomically:YES];
        }
        array = [NSMutableArray arrayWithContentsOfFile:path];
        BOOL exist = NO;
        for (int i=0; i<[array count]; i++) {
            if ([[[array objectAtIndex:i] objectForKey:@"id"] isEqualToString:prodId]) {
                exist = YES;
                //prodId = [NSString stringWithFormat:@"%@%i",prodId,i];
            }
        }   

        if(exist == NO) {
            [dict setObject:prodId forKey:@"id"];
            [dict setObject:prodName forKey:@"titolo"];
            [array insertObject:dict atIndex:0];    //sempre in testa l'ultimo elemento scaricato
            [array writeToFile:path atomically:YES];
        }

    }
    else {
        NSLog(@"decompression error");
        msg = @"An error has occurred";
    }

    //[myAlert release];
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"NYC.IT"
                                                    message:@"Download completed: new issue added in libray"
                                                   delegate:self 
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles: nil];
    [alert show];

    //[alert release];
}else {

    if(cancelDownload == YES) {

        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"NYC.IT"
                                                        message:@"Download stopped for user action" 
                                                       delegate:self 
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles: nil];
        [alert show];

    }else {

        NSString *errFile = [[self documentsDir:1] stringByAppendingPathComponent:@"errFile.html"]; 
        [receivedData writeToFile:errFile atomically:YES];
        NSLog(@"err : %@",errFile);
        NSLog(@"scrittura error file eseguita");

        NSLog(@"receipt non valido");
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"NYC.IT"
                                                  message:@"Downloading error: please retry later!" 
                                                  delegate:self 
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles: nil];
        [alert show];
    }


}
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
progressBar.hidden = YES;

// release the connection, and the data object
[connection release];
//[receivedData release];

提前致谢...

最佳答案

我不知道 x-code 但这是一个有用的库 http://www.winimage.com/zLibDll/minizip.html

关于ios - 用macHacha拼零件时解压出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6583331/

相关文章:

ios - 在 objective-c 中,为什么或如何将参数放在前面

android - DOM 元素的 TouchLeave

ios - 由于未捕获的异常 'NSRangeException' xcode 5 而终止应用程序

c++ - WebP 无损格式概述

ios - 在后台跟踪位置会导致应用程序被拒绝

ios - 如何在 firestore 数据库中使用 swift 更新数组中的对象( map )?

ios - 在上次提交后立即提交另一个 ipa 文件

ios - presentViewController 在 iOS 6 中工作但在 iOS 5 中不显示 View

algorithm - LZW 或 JBIG 是更好的图像无损压缩算法?

linux - 如何修改gzip压缩文件