【发布时间】:2014-06-26 06:47:57
【问题描述】:
(在 MAC OSX-Xcode 中)我尝试使用 NSURLConnection 类通过 FTP 读取文件,只要我的代码在主应用程序委托类 (AppDelegate) 中,但如果我在外部使用它(另一个 .h .m 文件),它就可以正常工作) 未调用连接委托。
有什么帮助吗!?
这是我的代码:
-(void)getURL {
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"ftp://.... connection string with file"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (connection) {
// Do something
} else {
// Inform the user that the connection failed.
NSLog(@"connection failed");
}
}
代表:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"didReceiveResponse");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"connectionDidFinishLoading");
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
//Getting file data
[receivedData appendData:data];
}
【问题讨论】:
标签: xcode ftp nsurlconnection nsurlconnectiondelegate nsconnection