如何在我的应用程序中实现网络错误警报? [英] How to implement network error alerts into my app?

查看:78
本文介绍了如何在我的应用程序中实现网络错误警报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要网络连接的基于视图的应用。我想添加代码,以便在网络不可用时我的应用程序出错。

I am developing a view based app that requires a network connection. I want to add code so that my app gives an error when a network is not available.

我无论是否将代码放入appdelegate或代码中是什么代码( .h / .m)和/或viewcontroller(.h / .m)

I am clueless as to, whether or what code to put into the appdelegate(.h/.m) and/or viewcontroller(.h/.m)

任何人都可以帮助我吗?

Can anyone help me?

提前致谢:)

推荐答案

你读过这篇文章

一旦你知道你离线了,你可能想要显示一个UIAlertView。

Once you know you're offline you just might wanna show an UIAlertView.

你可以将这个代码集成到你的appDelegate的方法应用程序:didFinishLaunchingWithOptions:。

You could integrate this code into the method application:didFinishLaunchingWithOptions: of your appDelegate.

我不建议使用测试网络连接这样的功能。它的一般问题是,即使您的应用程序测试它时可能还有连接,但它可能会稍后消失。因此,当您的应用确实需要使用网络,然后仔细处理错误情况并显示有意义的消息等时,我会尝试使用连接。

I would not recommend to use such a feature as "test for network connectivity". The general problem with it is, that even though you might have connectivity when your app tests for it, it might be gone a little later. So I would just try to use connectivity when your app really needs to use the network and then handle error cases carefully and display meaningful messages and so on.

这篇关于如何在我的应用程序中实现网络错误警报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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