如何停止 ASIHTTPRequest(使用 ARC)?
我使用 ARC,对于 ASIHTTPRequest-Files,我有特殊的编译器链接器标志,因此它们不使用 ARC。现在我创建一个像这样的 ASIHTTPRequest:
...
@property(非原子,强)ASIFormDataRequest *请求;
@syntesize 请求
...
self.request = [[ASIFormDataRequest alloc]initWithURL:[NSURL URLWithString:API3]];
self.request.delegate=self;
[self.request startAsynchronous];
如果视图在请求完成之前关闭,我会得到 EXEC_BAD_ACCESS,因为视图已经被释放。如果我打电话给
[self.requestclearDelegateAndCancel]
请求没有停止,应用程序仍然继续崩溃。 我尝试在主线程上调用clearDelegateAndCancel并使用performSelector afterDelay,但结果相同。 当我启用 ASIHTTPRequest 的 LOG 输出时,我看到方法被调用,并且 ASIHTTPRequest.m 中的内部函数 [self cancel] 被调用,但请求没有停止,我看到它是因为网络活动指示器。
还有其他人遇到这个问题,或者知道如何解决吗?
I use ARC, for the ASIHTTPRequest-Files I have the special compiler linker flag, so they don't use ARC. Now I create an ASIHTTPRequest like this:
...
@property(nonatomic,strong) ASIFormDataRequest *request;
@syntesize request
...
self.request = [[ASIFormDataRequest alloc]initWithURL:[NSURL URLWithString:API3]];
self.request.delegate=self;
[self.request startAsynchronous];
If the view closed before the request finished, I get a EXEC_BAD_ACCESS, because the view is already released. If I call a
[self.request clearDelegateAndCancel]
The request didn't stop and the App still continue to crash.
I tried to call clearDelegateAndCancel on the main Thread and with performSelector afterDelay, but with the same results.
When I enable the LOG output of ASIHTTPRequest, I see that the methods get called, and also the internal Function [self cancel] in ASIHTTPRequest.m is called, but the request didn't stop, I see it because of the Network Activity Indicator.
Does anyone else have this problem, or know how to solve?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是因为您的视图控制器(即 ASI 委托)不被 ASI 作为弧弱指针进行管理,因此当视图控制器被释放时不会自动更新为 nil。
您应该在 arc 视图控制器中实现 dealloc,以防止 ASI 回调不存在的委托(视图控制器)
,即使 viewDidUnload 也应该取消 ASI 请求清零,因此委托
that is probably because your viewcontroller, that is the ASI delegate, is not managed as an arc weak pointer by ASI, and therefore not automatically updated to nil when the viewcontroller gets deallocated.
You should implement dealloc in your arc viewcontroller in order to prevent ASI from calling back the non existing delegate (the viewcontroller)
even viewDidUnload should cancel the ASI request zeroing therefore the delegate
您可以为该类禁用 ARC
当您迁移项目以使用 ARC 时,-fobjc-arc 编译器标志将设置为所有 Objective-C 源文件的默认值。您可以使用特定类的-fno-objc-arc编译器标志来禁用该类的ARC。
在 Xcode 中,转到目标
Build Phases 选项卡
>打开Compile Sources组
以显示源文件列表>双击要为其设置标志的文件 >在弹出面板中输入-fno-objc-arc,然后单击“完成”。You can disable ARC for that one class
When you migrate a project to use ARC, the -fobjc-arc compiler flag is set as the default for all Objective-C source files. You can disable ARC for a specific class using the -fno-objc-arc compiler flag for that class.
In Xcode, go to target
Build Phases tab
> open theCompile Sources group
to reveal the source file list > double-click the file for which you want to set the flag > enter -fno-objc-arc in the pop-up panel, then click Done.