asihttprequest 使我的应用程序崩溃 [英] asihttprequest crashes my app

查看:19
本文介绍了asihttprequest 使我的应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于导航的应用程序.在主视图上按下一个按钮,然后我将一个新视图推送到导航控制器.所有非常基本的东西.

I have a navigation based app. Press a button on main view, then I push a new view to the navigation controller. All pretty basic stuff.

加载新视图时,我执行 ASIHTTPRequest 来获取一些 json 数据,这是一个图像 url 列表.然后我做一个 for 循环,创建一堆 ASIHTTPRequest,将它们添加到队列中,然后运行队列.

When the new view is loaded, I do an ASIHTTPRequest to fetch some json data, which is a list of image urls. Then I do a for loop, create a bunch of ASIHTTPRequests, add them to a queue and then run the queue.

但是如果我在队列完成之前点击后退按钮,应用程序崩溃,这个应用程序显示房屋并假设你选择了错误的房子,在显示任何照片之前快速点击返回,bumm crash.

But if I click on the back button before the queue is finished, the app crashes, this app displays houses and lets say you pick the wrong house, click back very quickly, before any photo is displayed, bumm crash.

此主题 http://groups.google.com/group/asihttprequest/browse_thread/thread/3d4815198aa889b9 很好地解释了我的问题,除了我确实取消了视图上的所有请求并卸载,将委托设置为 nil 并释放队列.

This thread http://groups.google.com/group/asihttprequest/browse_thread/thread/3d4815198aa889b9 explains my problem real well, except I do cancel all requests on view did unload, set delegate to nil and release the queue.

我还是崩溃了.如果我使用 3G,我几乎每次都会崩溃,但在 wifi 上很难让它崩溃,但非常可行.

Still I crash. I crash pretty much every time if I use 3G, but on wifi it is real hard to make it crash, but quite doable.

在几乎 80% 的情况下,调试器会跳转到 ASIHTTPRequest.m 中的这一行

In almost 80% instances the debugger jumps to this line in ASIHTTPRequest.m

(void)requestReceivedResponseHeaders:(NSMutableDictionary *)newResponseHeaders { 
  if ([self error] || [self mainRequest]) { return; }  
--> if (delegate && [delegate respondsToSelector:didReceiveResponseHeadersSelector]) {

它跳转到很多很多情况:

Many many cases it jumps to :

(void)requestReceivedResponseHeaders:(NSMutableDictionary *)newResponseHeaders { 
  if ([self error] || [self mainRequest]) { return; }    
---> if (delegate && [delegate respondsToSelector:didReceiveResponseHeadersSelector]) {  

在少数情况下,它会进入我的主循环

Ad in a handful of instances it goes to my main loop

int main(int argc, char *argv[]) {  
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 
--> int retVal = UIApplicationMain(argc, argv, nil, nil); with SIGBART error [pool release]; return retVal;  

我正在使用 MBP 和 MacPro、最新的 OS X、Xcode 4.0.2,并且我在除原装 iPhone 之外的所有苹果设备上进行测试.

I am using MBP and MacPro, latest OS X, Xcode 4.0.2 and I test on all apple devices except original iPhones.

我真的不想重写我的整个应用程序,但是还有什么可以与 ASIHTTPRequest 相比的吗?

I really don't want to re-write my whole app, but is there anything else out there that compares with ASIHTTPRequest ?

推荐答案

错误是delegate仍然被设置.

The error is that the delegate is still set.

我找到了两种方法来解决这个问题.

I have found 2 ways to fix this.

我认为丑陋的方式是您创建一个通用委托来处理所有网络流量并在应用程序首次运行时实例化.我实际上使用了应用程序委托并收听了 nsnotification 中心消息.它就像一个魅力,应用程序永远不会崩溃,但我认为它不是最佳的.

The way I consider ugly is that you make a universal delegate that does all network traffic and is instantiated when the app is first run. I actually used the app delegate and listen to nsnotification center messages. It works like a charm, the app never crashes, but I think it is not optimal.

最好的方法是不设置委托,不使用setDidFinishSelector",而是使用setCompletionBlock:^".这仅适用于运行 iOS 4.0 及更高版本的设备,这一比例超过 90-95% 并且还在增长.这只是一个很棒的方法,不会导致应用程序崩溃.

The best way is to not set the delegate and not use "setDidFinishSelector", but instead use "setCompletionBlock:^". This will only work on devices running iOS 4.0 and up, which is more than 90-95% and growing. This is just an awesome way and will not crash the application.

这篇关于asihttprequest 使我的应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆