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

查看:505
本文介绍了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数据,这是一个图像网址列表。
然后我做一个for循环,创建一堆ASIHTTPRequests,将它们添加到队列,然后运行队列。

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.

但是如果我点击按钮,在队列完成之前,应用程序崩溃,这个应用程序显示房子,并说,你选择错误的房子,很快点击回来,在任何照片显示之前,碰撞。

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.

仍然崩溃。

在接近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]) {

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

它进入我的主循环

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和我测试所有苹果

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 ?

推荐答案

错误是委托仍然设置。

修复此问题的方法。

我认为丑陋的方式是,你做一个万能委托,做所有的网络流量,并在应用程序第一次运行时实例化。我实际上使用应用程序委托并侦听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天全站免登陆