简体   繁体   English

iPhone,NSData,wifi与蜂窝网络

[英]iPhone, NSData, wifi vs. cellular network

I'm working on an application that downloads some data from the internet using NSData's initWithContentsOfURL method. 我正在开发一个使用NSData的initWithContentsOfURL方法从互联网下载一些数据的应用程序。 At startup I'm using some code from Apple's Reachability sample to check if a wifi connection is available; 在启动时,我正在使用Apple可达性示例中的一些代码来检查wifi连接是否可用。 if not, then the app just shows an error message and refuses to really start (as requested by my client). 如果不是,则该应用仅显示错误消息,并拒绝真正启动(按照我的客户的要求)。 All is working fine on iPod and iPad, but on iPhone, my client reports much, much slower download speeds, unless he turns on airplane mode, in which case download speeds are on par with iPod / iPad speeds. 一切在iPod和iPad上都可以正常工作,但是在iPhone上,我的客户报告下载速度要慢得多, 除非他打开飞行模式,在这种情况下,下载速度与iPod / iPad的速度相当。 So it seems that even though a wifi connection is available, the iPhone is probably using the cellular network to download the data. 因此,似乎可以使用wifi连接,但iPhone可能正在使用蜂窝网络下载数据。 Which is really weird. 真的很奇怪。 Does anyone have any idea about what I might be doing wrong? 有人对我可能做错的事有任何想法吗?

I believe your answer is SCNetworkReachability which you already have access to since you are using Apple's Reachability code. 我相信您的答案是SCNetworkReachability ,因为您正在使用Apple的Reachability代码,所以您已经可以使用它。

The SCNetworkReachability API allows an application to determine the status of a system's current network configuration and the reachability of a target host. SCNetworkReachability API允许应用程序确定系统当前网络配置的状态以及目标主机的可达性。 One of the flags returned by the API, kSCNetworkReachabilityFlagsIsWWAN, will tell you if a network connection to the target host uses the carrier network. API返回的标志之一kSCNetworkReachabilityFlagsIsWWAN将告诉您与目标主机的网络连接是否使用了运营商网络。 The Reachability sample code shows how to determine the active network connection. 可达性示例代码显示了如何确定活动的网络连接。

You could also use this to enforce WiFi if that's what you want. 如果需要的话,您也可以使用它来实施WiFi。 Have a look at UIRequiresPersistentWiFi 看看UIRequiresPersistentWiFi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM