简体   繁体   中英

How can i detect which type of network iam using in ios?

Is it possible to detect which type of network we are using like wifi, DSL, very poor network ?

Actually my app is crashing in Very poor, 100% loss and high latency network .

Is there any way to detect this so I can reduce the load with respect to network condition?

Please help me.

You can use to some extent Apple's Reachability

For example you can ping a particular IP address and derive some metrics from the result

You couldn't detect a quality of your connection. But there is a nice class Reachability which represents few useful methods to detect connection states.

Look at Reachability.m. it'll tell you whether you have any connection, and then tell you what kind of connection you have. It tells every thing about network.

Download Rechability here

you can download the Reachablity class. and add the following to check network type

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

if(remoteHostStatus == NotReachable) {NSLog(@"no");}
else if (remoteHostStatus == ReachableViaWiFiNetwork) {NSLog(@"wifi"); }
else if (remoteHostStatus == ReachableViaCarrierDataNetwork) {NSLog(@"cell"); }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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