Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 无提示解压_Objective C_Xcode_Macos - Fatal编程技术网

Objective c 无提示解压

Objective c 无提示解压,objective-c,xcode,macos,Objective C,Xcode,Macos,我正在创建一个应用程序,无需提示即可解压缩文件。我正在Vmaware中使用MAC OS 10.5映像 我是可可编程新手。我搜索了一些关于这个的代码,但它不起作用。我没有收到任何错误或警告消息。。请告诉我正确的解决方法。。 Zip文件未解压缩,一段时间后我的应用程序将关闭。我想解压文件,而不提示和使用任何第三方存档应用程序 我想将我的文件解压缩到其ZIP文件的相同位置 这是我的密码: /* Assumes sourcePath and targetPath are both valid, s

我正在创建一个应用程序,无需提示即可解压缩文件。我正在Vmaware中使用MAC OS 10.5映像

我是可可编程新手。我搜索了一些关于这个的代码,但它不起作用。我没有收到任何错误或警告消息。。请告诉我正确的解决方法。。 Zip文件未解压缩,一段时间后我的应用程序将关闭。我想解压文件,而不提示和使用任何第三方存档应用程序

我想将我的文件解压缩到其ZIP文件的相同位置

这是我的密码:

/* Assumes sourcePath and targetPath are both
   valid, standardized paths. */

// Create the zip task
NSTask * backupTask = [[NSTask alloc] init];
[backupTask setLaunchPath:@"/usr/bin/ditto"];
[backupTask setArguments:
    [NSArray arrayWithObjects:@"-c", @"-k", @"-X", @"--rsrc", 
    @"~/Desktop/demos.zip", @"~/Desktop", nil]];

// Launch it and wait for execution
[backupTask launch];
[backupTask waitUntilExit];

// Handle the task's termination status
if ([backupTask terminationStatus] != 0)
    NSLog(@"Sorry, didn't work.");

// You *did* remember to wash behind your ears ...
// ... right?
[backupTask release];
-谢谢
-向你问好

不确定这是否是您唯一的问题,但您需要展开路径中的波浪线(
~
)。通常这是由shell完成的,但是如果您不使用shell,则必须自己完成。幸运的是,有一个
NSString
方法可以做到这一点,因此您可以执行
[@“~/Desktop/demos.zip”stringByExpandingTildeInPath]
[@“~/Desktop”stringByExpandingTildeInPath]

我使用了您的代码并更改了一些选项。您已经指定了所有内容的完整路径

#import <Foundation/Foundation.h>

int main(int argc, char *argv[]) {

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

// Need to use the full path to everything
// In this example, I am using my Downloads directory
NSString *destination = [@"~/Downloads" stringByExpandingTildeInPath];
NSString *zipFile = [@"~/Downloads/demos.zip" stringByExpandingTildeInPath];


NSTask *unzip = [[NSTask alloc] init];
[unzip setLaunchPath:@"/usr/bin/unzip"];
[unzip setArguments:[NSArray arrayWithObjects:@"-u", @"-d", 
                     destination, zipFile, nil]];

NSPipe *aPipe = [[NSPipe alloc] init];
[unzip setStandardOutput:aPipe];

[unzip launch];
[unzip waitUntilExit];
[unzip release];


// You can get rid of all the NSLog once you have finish testing
NSData *outputData = [[aPipe fileHandleForReading] readDataToEndOfFile];
NSString *outputString = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];

NSLog(@"Zip File: %@", zipFile);
NSLog(@"Destination: %@", destination);
NSLog(@"Pipe: %@", outputString);
NSLog(@"------------- Finish -----------");
[outputString release];


[pool release];
return 0;
}
#导入
int main(int argc,char*argv[]){
NSAutoreleasePool*池=[[NSAutoreleasePool alloc]init];
//需要使用所有内容的完整路径
//在本例中,我使用的是我的下载目录
NSString*destination=[@“~/Downloads”stringByExpandingTildeInPath];
NSString*zipFile=[@“~/Downloads/demos.zip”stringByExpandingTildeInPath];
NSTask*解压=[[NSTask alloc]init];
[解压setLaunchPath:@/usr/bin/unzip];
[解压setArguments:[NSArray arrayWithObjects:@“-u”,“@“-d”,
目的地,zipFile,无]];
NSPipe*aPipe=[[NSPipe alloc]init];
[解压设置标准输出:aPipe];
[解压启动];
[解压waitUntilExit];
[解压释放];
//一旦完成测试,就可以删除所有NSLog
NSData*outputData=[[aPipe fileHandleForReading]READDATATONDOEFILE];
NSString*outputString=[[NSString alloc]initWithData:outputData编码:NSUTF8StringEncoding];
NSLog(@“Zip文件:%@”,zipFile);
NSLog(@“目的地:%@”,目的地);
NSLog(@“管道:%@”,输出字符串);
NSLog(@“-----完成-----------------”;
[输出字符串释放];
[池释放];
返回0;
}

+1最后一条评论谢谢米帕迪,我尝试了你的建议,但仍然不起作用。。文件未解压缩。您或任何人希望得到其他建议吗?提前感谢…-感谢汉克的黑青蛙,它现在起作用了。我需要找出这些代码的错误-当做