且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

asihttprequest 使我的应用程序崩溃

更新时间:2023-02-03 10:13:16

错误是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.