转到以下链接:
https://developer.apple.com/library/ios/samplecode/reachability/introduction/intro.html
下载并导入标头和实现文件,然后使用以下代码:
Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus status = [reachability currentReachabilityStatus];
if (status == ReachableViaWWAN)
{
NSLog(@"Cellular data");
}
Run Code Online (Sandbox Code Playgroud)
这个项目有点旧,您可能需要关闭 ARC 模式,请参阅以下答案: