0

(in MAC OSX- Xcode) I tried to read file by FTP using NSURLConnection class, it is work fine just if my code in main Application Delegate class (AppDelegate) but if i using it outside (another .h .m files) the connection delegate not called.

Any help!?

here is my code:

-(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");
}

}

Delegates:

- (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];

}

Nayef
  • 463
  • 5
  • 13

1 Answers1

0

Did you add the delegate <NSURLConnectionDelegate> to the view controller you are trying to use it in ?

for example

@interface ViewController : UIViewController <NSURLConnectionDelegate>
Kaiusee
  • 1,253
  • 1
  • 14
  • 28