请教一下,FTP开发,-(void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode始终没有回调

waderjy 发布于 01/30 16:55
阅读 87
收藏 0
iOS

请教一下,IOS的FTP开发,-(void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode方法始终没有被回调,不知道错在哪里,请大神指教。

 

#import "FTPDownload.h"

 

 

@interface FTPDownload()<NSStreamDelegate>

 

 

@property (nonatomic, strong)  NSInputStream *networkStream;

@property (nonatomic, assign)  NSString *filePath;

@property (nonatomic, strong)  NSOutputStream *fileStream;

 

 

@end

 

@implementation FTPDownload

 

-(void)startDownload {

    

    

    NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@selector(downloaddownload) object:nil];

    [thread start];

    

    

}

 

-(void)downloaddownload {

    

    //获得地址

    CFReadStreamRef ftpStream;

        

    NSString *link = @"ftp://*********";

        

        

    // 为文件存储路径打开流,filePath为文件写入的路径,hello为图片的名字,具体可换成自己的路径

    /*

    self.filePath = @"/Users/yuwei/Library/Containers/yw.multidownload/Data/Downloads/xxxxx.db";

    self.fileStream = [NSOutputStream outputStreamToFileAtPath:self.filePath append:NO];

    [self.fileStream open];

    */

        

        

    NSURL *url = [NSURL URLWithString:link];

    // 打开CFFTPStream

    ftpStream = CFReadStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url);

    self.networkStream = (__bridge NSInputStream *) ftpStream;

        

    // 设置代理

    self.networkStream.delegate = self;

    // 启动循环

    [self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

    [self.networkStream open];

        

    //释放链接

    CFRelease(ftpStream);

    //        CFBridgingRelease(ftpStream);

    

}

 

 

 

-(void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode{

    NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~%lu~~~~~~~~~~~~~~",(unsigned long)eventCode);

    NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~%lu~~~~~~~~~~~~~~",(unsigned long)eventCode);

    NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~%lu~~~~~~~~~~~~~~",(unsigned long)eventCode);

 

}

 

 

-(void)_stopReceiveWithStatus:(NSString *)statusString

{

    if (self.networkStream != nil) {

        [self.networkStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

        self.networkStream.delegate = nil;

        [self.networkStream close];

        self.networkStream = nil;

    }

    if (self.fileStream != nil) {

        [self.fileStream close];

        self.fileStream = nil;

    }

    if(statusString == nil){

        statusString = @"下载成功";

        //        _imageView.image = [UIImage imageWithContentsOfFile:self.filePath];//显示图片

    }

    

}

加载中
返回顶部
顶部