关于解压缩与ios cocoa

A:

先看cocoa的mac程序,怎么设计用来解压缩一个文件,这个原理有点类似我们采用zip/del命令来操作了,请看以下代码,很直接的NSTASK:

====

-(IBAction)unarchiveFile:(id)sender{    if(self.filePath == nil)
{        NSAlert *alert = [NSAlert alertWithMessageText:@"Error"                                         defaultButton:@"OK"                                       alternateButton:nil                                           otherButton:nil                             informativeTextWithFormat:@"You need to select a file path"];        [alert runModal];  //Alert the user and backout of the method if the file path hasn't been       
 return;    }   
 
 
 NSOpenPanel *oPanel = [[NSOpenPanel alloc] init]; //this lets the user choose where to extract the file to.     [oPanel setCanChooseFiles:NO];   
 [oPanel setCanChooseDirectories:YES];    [oPanel setCanCreateDirectories:YES]; 
//May as well do this, UX and all.    
NSInteger choice = [oPanel runModal];    if(choice == NSOKButton){        NSString *extractPath = [[NSString alloc] initWithString: [[oPanel URL]path]];        NSArray *arguments = [NSArray arrayWithObject:self.filePath];        NSTask *unzipTask = [[NSTask alloc] init];        [unzipTask setLaunchPath:@"/usr/bin/unzip"]; //this is where the unzip application is on the system.        [unzipTask setCurrentDirectoryPath:extractPath]; //this means we only have to pass one argument, the path to the zip.        [unzipTask setArguments:arguments];        [unzipTask launch];    }}
NSOPENPanel/ 用于打开文件/选择后canchoosefile,然后判断选择的正确性/choice=[oPanel runModal].

建立一个task后,我们可以执行参数(先要设置参数);最后调用unziptask launch,但如何确保执行成功的。

You can only use an instance of NSTask once. Yeah. Once you’ve run your NSTask, you need to create a new one.。。。

唯一运行任务,需要检测数据。。。


B:由于ios上没有NSTASK,所以需要考虑另外一套方式,最好的是在下载,复制过程中就完成了解压缩:

1.

I am developing an application in which I am getting a zipped XML file from web service. Now I need to unzip it and I have to parse it. How can I unzip an XML file coming from web service

还是需要下载后操作

2.

看起来没有那么好的下载过程就可以unzip

i can read html files now but how to download a zip file and extract it locally so that i can use that in my app plz 

http://code.google.com/p/ziparchive/

ZipArchive is an Objective-C class to compress or uncompress zip files, which is base on open source code "MiniZip".

It can be used for iPhone application development, and cocoa on Mac OSX as well.

不晓得这个压缩是不是统一规范的,否则双方不通

你可能感兴趣的:(ios,cocoa,File,application,Path,download)