Detect carrier connection type (3G / EDGE / GPRS)

后端 未结 4 1660
别那么骄傲
别那么骄傲 2020-11-27 13:21

How can i get the type of connection of a carrier network?

  • I\'m able to get if connection is WIFI or WWAN using Reachability class
  • I

4条回答
  •  北海茫月
    2020-11-27 13:52

    I am working on an iPhone application that requires the ability to recognize which type of internet connection is currently being used (Wifi, 3G, Edge, etc). I found a simple way to check by using Apples Reachability sample code. There seems to be a shortage of information about this online, I hope this can help someone.

    First copy Reachability.m/.h into your project and include #include "Reachability.h" into your class.

    Reachability *reach = [[Reachability alloc]init];
    if (reach.internetConnectionStatus == NotReachable) {
        NSLog(@"No Connection Found");
    } else if (reach.internetConnectionStatus == ReachableViaCarrierDataNetwork) {
        NSLog(@"3G or Edge");
    } else if (reach.internetConnectionStatus == ReachableViaWiFiNetwork) {
        NSLog(@"Wifi Connection");
    }
    [reach release];
    

    This code may not be the best way to accomplish this, but it appears to be the most simple approach.

提交回复
热议问题