应用程序将如何了解 iPhone 中互联网连接的可用性? [英] How Application will get to know Availability of internet connection in iPhone?

查看:57
本文介绍了应用程序将如何了解 iPhone 中互联网连接的可用性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Iphone 应用程序开发的新手,所以我有几个问题.帮我解决这个问题.

I am new to Iphone app development so i am having some couple of questions. Help me out on this.

1) 如何,iphone 上的所有应用程序都会知道,当用户在设置中打开 wifi 按钮或蜂窝按钮时,有可用的互联网连接?

2)如何区分wifi连接和蜂窝连接?

3) iphone 中是否也有类似 android 概念的广播接收器机制?

1) How, all the application on iphone will get to know that, there is internet connection available when user switches on wifi button or Cellular button in settings?

2) How to differentiated between wifi connection and cellular connection?

3) Are there any Broadcast receiver mechanism in iphone similar to android concepts as well?

我在谷歌上搜索了许多互联网连接的链接,并了解了 iPhone 中的 Reachibilty 类,但我无法清楚地了解它是如何工作的?如果有人可以给我详细解释可达性的链接,那就太好了.或任何其他机制来实现上述功能.

I had googled many links for internet connectivity, and got to know about Reachibilty class in iPhone, but i was not able to get clear picture on how it works? if any once can give me link which explains me in detail about reachibility, that would be great. or any other mechanism to achieve above functionality.

我正在编写一个应用程序,我需要开始上传一些数据,当应用程序知道有可用连接时,即使应用程序在后台或前台也应该发生这种情况.

I am writing an application, where i need to start uploading some data, when application will get to know that there is connection available, and this should happen even when application is in background or in foreground.

提前致谢

推荐答案

试试这个示例代码 示例
https://github.com/tonymillion/Reachability

Try with this sample code Sample and
https://github.com/tonymillion/Reachability

它还可以让您检查是否启用了 WiFi:

It will also allow you to check if WiFi is enabled:

Reachability* reachability = [Reachability sharedReachability];
[reachability setHostName:@"www.google.com"];    // set your host name here
NetworkStatus remoteHostStatus = [reachability remoteHostStatus];

if(remoteHostStatus == NotReachable) { }
else if (remoteHostStatus == ReachableViaWiFiNetwork) { }
else if (remoteHostStatus == ReachableViaCarrierDataNetwork) { }

这篇关于应用程序将如何了解 iPhone 中互联网连接的可用性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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