首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSURLDownload未启动

NSURLDownload未启动
EN

Stack Overflow用户
提问于 2010-02-22 14:44:10
回答 1查看 790关注 0票数 1

我正在尝试使用NSURLDownload下载网址,但它不能开始下载。在继续之前,我必须说我使用的是GNUStep。

我的项目概述如下:

MyClass.h:

代码语言:javascript
复制
@interface MyClass : Object {

}

-(void)downloadDidBegin:(NSURLDownload*)download;
-(void)downloadDidFinish:(NSURLDownload*)download;

@end

Main.m

代码语言:javascript
复制
int main()
{
   NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

   NSLog(@"creating url");
   NSURL* url = [[[NSURL alloc] initWithString:@"http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/NSURLRequest_Class.pdf"] autorelease];

   NSLog(@"creating url request");
   NSURLRequest* url_request = [[[NSURLRequest alloc] initWithURL:url] autorelease];

   NSLog(@"creating MyClass instance");
   MyClass* my_class = [[MyClass alloc] init];

   NSLog(@"creating url download");
   NSURLDownload* url_download = [[[NSURLDownload alloc] initWithRequest:url_request
                                                                delegate:my_class] autorelease];

   [pool drain];
}

我在MyClass中的两个函数上都有NSLog,但它们都没有命中。我必须做什么才能开始下载?或者这是GNUStep的问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-02-22 22:17:02

NSURLDownload在后台下载,因此对initWithRequest:delegate:的调用会立即返回。

除非您的程序将控制传递给run循环(对于应用程序,这是自动处理的,但对于工具,必须手动完成),否则它将只执行main()函数的其余部分并终止。

此外,发送给您的委托的消息是从run循环中发送的,因此即使main()没有立即退出,您的委托仍然不会接收downloadDidBegin:downloadDidFinish:,除非您的代码首先调用NSRunLoop的run方法之一。

将以下行添加到代码中,紧接在[pool drain];之前

[[NSRunLoop currentRunLoop] run];

有关run循环的更多信息,请查看Thread Programming Guide

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2309249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档