Delegate无法正确工作(有关Ftp控制)
2014-04-26 22:48
435 查看
最近研究Ftp上传、下载、创建、删除
因为NSStream没有提供删除的接口,要用CFURLDestroyResource删除,所以就用了国外人写的东西BlackRaccoon。里面的调用机制,使用委托协议等方法用的很好,值得学习。将其中的主要类的内容大概说下:
BRRequest类:主要存储空间及用户数据,BRRequestDelegate协议的定义
BRStreamInfo类:流的读、写
四个ftp功能类:上传、下载、创建、删除,继承于BRRequest类
在使用中发现问题:
在下载文件中发现,当数据流已经读下来了,但到BRStreamInfo类的(问题和原因都写在下面了)
- (void)streamComplete:(BRRequest *)request
{
writeWLLog(@"BRStreamInfo.streamComplete");
//下面这句话在这里程序里总是失败
//request.delegate无法实现委托
//原因找到了!因为BRRequest.h里@property (strong) id <BRRequestDelegate> delegate;
//不能用weak,要用strong
[request.delegate requestCompleted: request];
[request.streamInfo close: request];
}
解决方法:
在BRRequest.h中修改:
@property (strong) id <BRRequestDelegate> delegate;这里的strong是非常重要的一个东东,原来是
//weak,但会造成streaminfo里的streamComplete函数里的
//[request.delegate requestCompleted: request];不工作,原因就是在指针委托被摧毁了(释放)
感谢外国友人,下面是他们的原文!
https://github.com/lloydsargent/BlackRaccoon/issues/41
I've implemented an FTPHelper class, that does the FTP communication for me using BlackRaccoon, however, all the delegate/required methods are not called.
I'm trying to download a database file from my FTP server, it's not storing though, it did download it, since the data isn't communicated back requestCompleted.
I'm sure that my FTP server is working, and that the data is being transferred because I placed print statements in BRStreamInfo.m. In my understanding, when the stream is complete it should call requestCompleted according to the following snippet
This is my FTP helper method, FTP request information are stored as constants:
I found out what the problem is, it turns out that the pointer delegate is destroyed during the download process. I changed it's property from (weak) to (strong) and now it works.
In BRRequest.h:
因为NSStream没有提供删除的接口,要用CFURLDestroyResource删除,所以就用了国外人写的东西BlackRaccoon。里面的调用机制,使用委托协议等方法用的很好,值得学习。将其中的主要类的内容大概说下:
BRRequest类:主要存储空间及用户数据,BRRequestDelegate协议的定义
BRStreamInfo类:流的读、写
四个ftp功能类:上传、下载、创建、删除,继承于BRRequest类
在使用中发现问题:
在下载文件中发现,当数据流已经读下来了,但到BRStreamInfo类的(问题和原因都写在下面了)
- (void)streamComplete:(BRRequest *)request
{
writeWLLog(@"BRStreamInfo.streamComplete");
//下面这句话在这里程序里总是失败
//request.delegate无法实现委托
//原因找到了!因为BRRequest.h里@property (strong) id <BRRequestDelegate> delegate;
//不能用weak,要用strong
[request.delegate requestCompleted: request];
[request.streamInfo close: request];
}
解决方法:
在BRRequest.h中修改:
@property (strong) id <BRRequestDelegate> delegate;这里的strong是非常重要的一个东东,原来是
//weak,但会造成streaminfo里的streamComplete函数里的
//[request.delegate requestCompleted: request];不工作,原因就是在指针委托被摧毁了(释放)
感谢外国友人,下面是他们的原文!
https://github.com/lloydsargent/BlackRaccoon/issues/41
I've implemented an FTPHelper class, that does the FTP communication for me using BlackRaccoon, however, all the delegate/required methods are not called.
I'm trying to download a database file from my FTP server, it's not storing though, it did download it, since the data isn't communicated back requestCompleted.
I'm sure that my FTP server is working, and that the data is being transferred because I placed print statements in BRStreamInfo.m. In my understanding, when the stream is complete it should call requestCompleted according to the following snippet
- (void)streamComplete:(BRRequest *)request { NSLog(@"Stream Complete"); [request.delegate requestCompleted: request]; NSLog(@"Data tranferred back to FTP helper requestCompleted"); [request.streamInfo close: request]; }
This is my FTP helper method, FTP request information are stored as constants:
I found out what the problem is, it turns out that the pointer delegate is destroyed during the download process. I changed it's property from (weak) to (strong) and now it works.
In BRRequest.h:
@property (weak) id <BRRequestDelegate> delegate; //Change the above to the below @property (strong) id <BRRequestDelegate> delegate;
相关文章推荐
- 应用程序无法启动,因为应用程序的并行配置不正确。有关详细信息,请参阅应用程序事件日志,或使用命令行 sxstrace.exe 工具
- 操作无法完成.键入的打印机名不正确,或者指定的打印机没有连接到服务器上.有关详细信息,请单帮助
- “应用程序无法启动,因为应用程序的并行配置不正确。有关详细信息,请参阅应用程序事件日志,或使用命令行 sxstrace.exe 工具” 的解决方法
- 操作无法完成.键入的打印机名不正确,或者指定的打印机没有连接到服务器上.有关详细信息
- skynet clientsocket 导致 io.read 无法正确工作的问题
- crystal report(水晶报表) 在vista 下无法预览,与UAC(用户帐号控制)有关
- win7(32 bit) + IE8 环境,IE8无法弹窗(错误提示:“此网页上的错误可能会使它无法正确运行”),有关的系统注册信息损坏——解决方法
- ftp账号密码正确无法登陆xftp,xftpbug
- 操作无法完成.键入的打印机名不正确,或者指定的打印机没有连接到服务器上.有关详细信息,请单帮助
- 遇到问题-----ftp---windows----打开FTP文件夹出错--windows无法访问此文件夹。请确保输入的文件名是否正确,并且您有权访问此文件
- win7下 LoadRunner 11 LoadLibrary(mybean.dll) failed : 应用程序无法启动,因为应用程序的并行配置不正确。有关详细信息,请参阅应用程序事件日志,或使
- 工作问题积累(十一)如何解决"应用程序无法启动,因为应用程序的并行配置不正确"问题
- 程序打包,"错误:应用程序无法启动,因为应用程序的并行配置不正确。有关详细信息,请参阅应用程序事件日志,或使用命令行sxstrace.exe"工具解决办法
- ftp文件夹错误:windows无法访问此文件夹,请确保输入的文件名是否正确,并且您有权访问此文件
- 操作无法完成.键入的打印机名不正确,或者指定的打印机没有连接到服务器上.有关详细信息,请单帮助
- 应用程序无法启动,因为应用程序的并行配置不正确,有关详细信息,请参阅应用程序事件日志,或使用命令行sxstrace.exe工具
- vc2013 时错误 应用程序无法启动,因为应用程序的并行配置不正确。有关详细信息,请参阅应用程序事件 日志,或使用命令行 sxstrace.exe 工具。
- filezilla ftp无法确定拖放操作目标 由于shell未正确安装的解决办法
- 解决ftp连接出现 无法从控制 Socket 读取。Socket 错误 = #10054。
- 关于“无法从控制 Socket 读取。Socket 错误 = #10054”的解析 FTP主动传输被动传输