Internet连接:未调用NURLConnection didFailWithError方法 [英] Internet Connection : NURLConnection didFailWithError method not called

查看:116
本文介绍了Internet连接:未调用NURLConnection didFailWithError方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开发Iphone应用程序并通过Iphone Simulator测试时遇到问题。

I face a problem when develop an Iphone application and test it through Iphone Simulator.

在我的Iphone应用程序中,有一个按钮。当我点击此按钮时,代码将检查Iphone是否连接到互联网。如果已连接,则它将从服务器开始加载数据,然后将数据插入到应用程序的本地数据库中。并显示一个显示已加载数据的视图。如果未连接互联网,则会调用didFailWithError方法并弹出警报以提醒用户没有互联网连接。

In my Iphone application, there exist a button. When I click on this button, the code will check whether the Iphone is connected to internet or not. If is connected, then it will start load data from server and then insert data to my application's local database. And show a view which display the loaded data. If internet is not connected, the didFailWithError method will called and pop up a alert to alert user "no internet connection".

但我的问题是当我的互联网连接时Mac打开,我单击该按钮,数据将成功加载并显示一个包含已加载数据的视图。然后我关闭了那个视图,关闭了Mac上的互联网连接,然后我再次单击该按钮,似乎没有调用didFailWithError。并且视图也会显示给用户,但数据不会更新,看起来与第一次加载的数据相同。

But my problem is when the internet connection on my Mac is on, and I click that button, the data will be loaded successfully and display a view which consists the loaded data. Then I close that view, and off the internet connection on Mac, then I click that button again, the didFailWithError seems not get invoked. And a view will displayed to user too but the data is not updated, it seems look same as the data loaded from first time.

另一种情况是,一次我开始使用应用程序,首先关闭Mac上的互联网连接,然后第一次点击该按钮,调用didFailWithError并提醒用户没有互联网连接。

And for another case that is,once I start use the application, and off the internet connection on Mac first, and click that button for first time, the didFailWithError is invoked and alert user "No Internet Connection".

那么,之前有人遇到过这种问题吗?或者任何人有意见,建议和解决方案?

So, anyone encountered this kind of problem before? Or anyone have comments, suggestion and solutions?

非常感谢您的回复。谢谢。

Really appreciate your reply. Thanks.

推荐答案

所以你可能已经找到了问题的解决方案,因为这是一个非常古老的问题,但是我发布了你的答案需要它。

So probably you have got the solution to your problem as this is very old question but I post answer incase you still need it.

它的简单解决方案是使用苹果的 reachabillity 类//developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007324\"rel =nofollow>可达性

The simple solution for it is use the reachabillity class of apple's Reachability

只需使用此示例来解决您的问题。

just use this example to solve your problem.

这篇关于Internet连接:未调用NURLConnection didFailWithError方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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