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全部内容,希望文章能够帮你解决关于解压缩与ios cocoa所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)