Internet Connection : NURLConnection didFailWithError method not called

六月ゝ 毕业季﹏ 提交于 2020-01-25 12:29:21

问题


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

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".

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.

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.


回答1:


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.

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

just use this example to solve your problem.



来源:https://stackoverflow.com/questions/6953204/internet-connection-nurlconnection-didfailwitherror-method-not-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!