可可问题 - NSTask 不起作用
NSTask 不工作;我认为这与争论有关。这是我的代码:
- (IBAction)downloadFile:(id)sender {
// allocate our stuff :D
progressIndication = [[NSProgressIndicator alloc] init];
NSTask *downloader = [[NSTask alloc] init];
// set up the downloader task
[downloader setLaunchPath:@"/usr/bin/curl"];
[downloader setArguments:[NSArray arrayWithObject:[NSString stringWithFormat:@"-LO %@", downloadURL]]];
// go to the Desktop!
system("cd ~/Desktop");
// start progress indicator
[progressIndication startAnimation:self];
// download!
[downloader launch];
// stop the progress indicator, everything is done! :D
[progressIndication stopAnimation:self];
}
谢谢
NSTask isn't working; I think it has to do with the arguments. Here is my code:
- (IBAction)downloadFile:(id)sender {
// allocate our stuff :D
progressIndication = [[NSProgressIndicator alloc] init];
NSTask *downloader = [[NSTask alloc] init];
// set up the downloader task
[downloader setLaunchPath:@"/usr/bin/curl"];
[downloader setArguments:[NSArray arrayWithObject:[NSString stringWithFormat:@"-LO %@", downloadURL]]];
// go to the Desktop!
system("cd ~/Desktop");
// start progress indicator
[progressIndication startAnimation:self];
// download!
[downloader launch];
// stop the progress indicator, everything is done! :D
[progressIndication stopAnimation:self];
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实不需要使用
curl
来执行此操作;只需使用NSData
更轻松地完成任务:如果您坚持需要使用
curl
来完成此任务,您将必须修复您的代码,但这并不'由于多种原因无法工作。首先,你的论点是错误的。你应该有以下代码:其次,
system("cd ~/Desktop")
没有意义;摆脱它。最后,
NSTask
并发运行。[downloader launch]
开始操作,您的代码将继续。应该是:You really don't need to use
curl
to do this; just useNSData
to accomplish the task much more easily:If you insist you need to use
curl
for this, you're going to have to fix your code, which doesn't work for several reasons. First and foremost, your arguments are wrong. You should have the following code:Second,
system("cd ~/Desktop")
is meaningless; get rid of it.Lastly,
NSTask
runs concurrently.[downloader launch]
starts the operation, and your code continues. It should be: