(MAC OSX-Xcodeで)NSURLConnectionクラスを使用してFTPでファイルを読み込もうとしましたが、私のコードがメインのApplication Delegateクラス(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];
}