uitableview - Is that effective to check the internet Reachability in iOS? -



uitableview - Is that effective to check the internet Reachability in iOS? -

assuming have net connection, i' utilize code know if device connected via wifi or not :

+ (bool)haswificonnection { reachability *reachability = [reachability reachabilityforinternetconnection]; [reachability startnotifier]; networkstatus status = [reachability currentreachabilitystatus]; if (status == reachableviawifi) { homecoming yes; } else { homecoming no; } }

is code fast run?

i'm using when generating urls pictures (so know if load high or low resolution pictures). pictures displayed in list view (3 per line). when scroll list function called several times per second. efficient?

if u dont want utilize reachability class utilize next code.

@interface cmlnetworkmanager : nsobject +(cmlnetworkmanager *) sharedinstance; -(bool) hasconnectivity; @end

implementation

@implementation cmlnetworkmanager +(cmlnetworkmanager *) sharedinstance { static cmlnetworkmanager *_instance = nil; @synchronized(self) { if(_instance == nil) { _instance = [[super alloc] init]; } } homecoming _instance; } -(bool) hasconnectivity { struct sockaddr_in zeroaddress; bzero(&zeroaddress, sizeof(zeroaddress)); zeroaddress.sin_len = sizeof(zeroaddress); zeroaddress.sin_family = af_inet; scnetworkreachabilityref reachability = scnetworkreachabilitycreatewithaddress(kcfallocatordefault, (const struct sockaddr*)&zeroaddress); if(reachability != null) { //networkstatus retval = notreachable; scnetworkreachabilityflags flags; if (scnetworkreachabilitygetflags(reachability, &flags)) { if ((flags & kscnetworkreachabilityflagsreachable) == 0) { // if target host not reachable homecoming no; } if ((flags & kscnetworkreachabilityflagsconnectionrequired) == 0) { // if target host reachable , no connection required // we'll assume (for now) on wi-fi homecoming yes; } if ((((flags & kscnetworkreachabilityflagsconnectionondemand ) != 0) || (flags & kscnetworkreachabilityflagsconnectionontraffic) != 0)) { // ... , connection on-demand (or on-traffic) if // calling application using cfsocketstream or higher apis if ((flags & kscnetworkreachabilityflagsinterventionrequired) == 0) { // ... , no [user] intervention needed homecoming yes; } } if ((flags & kscnetworkreachabilityflagsiswwan) == kscnetworkreachabilityflagsiswwan) { // ... wwan connections ok if calling application // using cfnetwork (cfsocketstream?) apis. homecoming yes; } } } homecoming no; } @end

use bool method class shared instance ever want

ios uitableview reachability

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -