iphone SDK detect Wifi and Carrier network

好久不见. 提交于 2019-11-28 16:55:12

That sample is exactly what you need.

Look at Reachability.m. it'll tell you whether you have any connection, and then tell you what kind of connection you have.

Massimo Cafaro

The Reachability example may be overkill if you just want to detect whether or not you are connected, and what type of connection you are using if you are connected. Indeed the example also contains code showing how to setup and use callbacks that notify you of state changes.

For a snippet of source code telling you exactly if you are connected or not, and what type of connection you are using, you may want to take a look at my answer to a similar question, posted here.

Mina Mikhael

Once you make a request to any web resource, the iPhone uses any connection it finds, it uses wifi ( as a higher priority ), and if wifi is not connected it uses carrier network. There's no code settings thats preventing carrier network.

All you have to do:

  • Check the signal at the testing place.
  • Check the link you are trying to reach on safari, to make sure its not your app that have the problem.
  • Contact your carrier support if the link is not working on safari ( for sure using the carrier network )

These techniques are useful, but keep in mind that the device's path to the Internet might consist of several different types of connections. For example, a iPhone or iPod touch might be using WiFi to connect to a mobile hotspot, which in turn has its own 3G wireless connection. So it is not safe to assume that the presence of a WiFi connection implies higher bandwidth than 3G.

Reachability (both Apple's sample code, and other people's similar code, and the underlying SCNetworkReachability will tell you either that there is no internet access, or that you will get internet access through WiFi, or that you will get internet access through mobile data.

If you have both WiFi and mobile data available, it will tell you "WiFi". There is no way to find out that mobile data is available when you have WiFi. (You can easily find out that mobile data is available when there is no WiFi). You cannot find out if Airplane mode is turned on (which would be different from WiFi and mobile data turned off).

WiFi available doesn't guarantee that a download will use WiFi and not mobile data. You might start a download at home, leave a minute later, WiFi disappears, and iOS will happily continue downloading through 3G. You can set a flag in the download call to disallow 3G. The error code will be -1009 = No internet access, no mention that 3G would have been available.

Using CTTelephonyNetworkInfo you can find out that you are on a device that could have mobile data (not an iPod Touch or iPad without mobile data, and there is a SIM in the device).

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