¿Tengo conexión a Internet?

Share


En muchas ocasiones, será conveniente comprobar, antes de realizar cualquier otra acción, que tipo de conexión a Internet tengo disponible, WIFI, 3G, celular, etc...

En las pruebas que previamente he realizado, he comprobado que ante la situación de no tener conexión WIFI ó 3G, el dispositivo utiliza la conexión celular del movil (la utilizada para hacer y recibir llamadas), para conectarse a Internet, eso si, a una velocidad mucho más inferior que las otras.

Por lo tanto, el siguiente fragmento de código, gracias al framework SystemConfiguration.framework, nos permite conocer si tenemos conexión:

C++:
  1. SCNetworkReachabilityFlags flags;
  2.  
  3. SCNetworkReachabilityRef reachability =  SCNetworkReachabilityCreateWithName(NULL, @"http://www.iphonesoftware.es");
  4.  
  5. BOOL gotFlags = SCNetworkReachabilityGetFlags(reachability, &flags);
  6.  
  7. CFRelease(reachability);
  8.  
  9. if (!gotFlags) {
  10.  
  11. bConnectionIsReachable = NO;
  12.  
  13. }
  14.  
  15. else
  16.  
  17. {
  18.  
  19. BOOL isReachable = flags & kSCNetworkReachabilityFlagsReachable;
  20.  
  21. BOOL noConnectionRequired = !(flags & kSCNetworkReachabilityFlagsConnectionRequired);
  22.  
  23. if ((flags & kSCNetworkReachabilityFlagsIsWWAN)) {
  24.  
  25. noConnectionRequired = YES;
  26.  
  27. }
  28.  
  29. bConnectionIsReachable = (isReachable && noConnectionRequired) ? YES : NO;
  30.  
  31. }

 

Para empezar, crearemos una conexión mediante SCNetworkReachabilityCreateWithName, la cual será examinada para establecer si tenemos conexión o no. Después, comprobaremos el estado mediante una serie de flags, utilizando la función SCNetworkReachabilityGetFlags. Dichos flags serán evaluados comparando su valor con alguno de los del siguiente enumerado:

C++:
  1. enum {
  2.  
  3.    kSCNetworkReachabilityFlagsTransientConnection    = 1<<0,
  4.  
  5.    kSCNetworkReachabilityFlagsReachable        = 1<<1,
  6.  
  7.    kSCNetworkReachabilityFlagsConnectionRequired    = 1<<2,
  8.  
  9.    kSCNetworkReachabilityFlagsConnectionAutomatic    = 1<<3,
  10.  
  11.    kSCNetworkReachabilityFlagsInterventionRequired    = 1<<4,
  12.  
  13.    kSCNetworkReachabilityFlagsIsLocalAddress    = 1<<16,
  14.  
  15.    kSCNetworkReachabilityFlagsIsDirect        = 1<<17,
  16.  
  17.    kSCNetworkReachabilityFlagsIsWWAN        = 1<<18,
  18.  
  19. };

 

Desactiva la conexión WIFI, 3G, ó incluso el operador de tu iPhone para realizar las pruebas.

 

banner ad

Leave a Reply

  • Buy Cheapest diazepam Now 24/Internet)(safe Pharmacy. Best Online.
  • Buy Cheapest tramadol cod delivery Now Top Online Pharmacy. Best Drugstore.
  • Buy Cheap diuretics without prescription Now Best Internet. The Largest Internet Pharmacy.
  • Buy Cheapest valium online prescription Now Best Drugstore. Cheap Pharmacy Online.
  • ultram 50mg Online Without Prescription Best Prices. Pharmacy Store.
  • viagra suppliers Online Without Prescription Best Online. Pharmacy Store.
  • Buy Cheapest viagra on line pharmacy Now Cheap Pharmacy Online. Best Internet.
  • Buy Cheap valium without a precription Now Cheap Prescription Drugs. Guaranteed Shipping.
  • Buy Cheapest cialis overnight Now Special Prices For cialis overnight! Best Internet.
  • Buy Cheap cialis woman Now Online Medical Shop. Cheap Prescription Drugs.
  • Buy Cheap buy alprazolam now Now Cheap Online Pharmacy. Cheap Pharmacy Online.
  • Buy Cheap atorvastatin buy Online Best Drugstore. Online Prices For atorvastatin buy!
  • Buy Cheap sildenafil oral jelly Now Internet Prices For sildenafil oral jelly! Best Internet.
  • Buy Cheap nexium purchase Online No Prescription Needed. Best Drugstore.
  • Buy Cheapest viagra patch Online Cheap Prescription Drugs. Best Online.
  • Buy Cheap drug store pharmacy online Now Best Drugstore. Online Prices For drug store pharmacy online!
  • Buy Cheap what is the generic for viagra Online Internet Prices For what is the generic for viagra! Best Prices.
  • Buy Cheap where can i buy arthritis drugs Now Free Viagra Pills! No Prescription Needed.
  • Buy Cheapest weight loss medicine online prescrition Now Low Prices. Discount Pharmacy Online.
  • Buy Cheapest buy finasteride online Now Cheap Online Pharmacy. WorldWide Shipping.
  • Buy Cheapest infertility treatment drugs Online Cheap Online Pharmacy. Best Internet.
  • Buy Cheap levitra description Online Guaranteed Shipping. Top Online Pharmacy.
  • tadalafil soft tabs Online Without Prescription Pharmacy Store. Best Drugstore.
  • Buy Cheapest weight loss no prescription Now Best Prices. Drugs, Health And Beauty.
  • Buying Cheap cialis safety. Offshore Rx, Best Prices. Guaranteed Shipping.
  • Buy Cheapest zetia cost Now 100% Satisfaction Guaranteed. Best Online.
  • Buy Cheap order cialis online Now The Largest Internet Pharmacy. Low Prices.
  • Buy Cheap pain products Now Discount Pharmacy Online. Guaranteed Shipping.
  • Buy Cheapest levitra information Now Best Online. Internet Prices For levitra information!
  • Buy Cheapest generic cialis overnight delivery Now Free Viagra Pills! 24/Online Pharmacy.
  • Buy Cheapest side effects from viagra Online Low Prices. Internet Prices For side effects from viagra!
  • Buy Cheap chlamydia antibiotics Online WorldWide Shipping. Guaranteed Shipping.
  • Buy Cheapest online pharmacy in canada Online WorldWide Shipping. Free Viagra Pills!
  • Buy Cheap tramadol worldwide Online No Prescription Needed. Best Internet.
  • Buy Cheap levitra online order Online Discount Online Pharmacy. Pharmacy Store.
  • Buy Cheap buy generic levitra cheap Online Guaranteed Shipping. Cheap Online Pharmacy.
  • Buy Cheap muscle relaxants otc Now WorldWide Shipping. Discount Pharmacy Online.
  • Buy Cheapest pharmacy diflucan Now Cheap Pharmacy Online. Pharmacy Store.
  • Buy no prescription ultram Online Without Prescription. Best Drugstore. Low Prices.
  • Buy Cheapest promethazine side effects Online Best Internet. Drugs, Health And Beauty.
  • Buy Cheap drug store coupon Online The Largest Internet Pharmacy. Low Prices.
  • Buy Cheap vitamin shoppes Now Free Viagra Pills! Online Prices For vitamin shoppes!
  • Buy Cheap pain meds online without a prescription Now Low Prices. 24/Internet)(safe Pharmacy.
  • Buy Cheap foot pain products Online Top Online Pharmacy. 24/Online Pharmacy.
  • Buy Cheap 30 mg phentermine Now Pharmacy Store. The Largest Internet Pharmacy.
  • Buy Cheap products for back pain Now Free Viagra Pills! Cheap Pharmacy Online.
  • Buy Cheap antianxiety meds Now Free Viagra Pills! Online Medical Shop.
  • Buy Cheapest obesity self help Now Top Online Pharmacy. 24/Online Pharmacy.
  • Buy Cheap genric viagra Online WorldWide Shipping. Guaranteed Shipping.
  • Buy Cheapest soft tabs viagra Now Top Online Pharmacy. Online Medical Shop.
  • india drug sales on line Online Without Prescription Online Medical Shop. Low Prices.
  • Buy Cheap buy anti anxiety Online No Prescription Needed. Best Internet.
  • Buy Cheapest cialis generic overnight state united Online Buy Medications Online. Best Online.
  • Buy Cheap cialis gel Now Online Prices For cialis gel! Online Medical Shop.
  • Buy Cheap buy levitra us Online Best Online. Discount Online Pharmacy.
  • Buy Cheap mexico pharmacies Online Online Prices For mexico pharmacies! Best Drugstore.
  • Buy Cheap prescription weight loss drugs Now Order Cheap Meds Without Rx. Best Internet.
  • buy sildenafil citrate Online Without Prescription Best Prices. Best Internet.
  • Buy Cheap extreme weight loss Now WorldWide Shipping. 24/Online Pharmacy.
  • Buy Cheapest mexico levitra Online Best Internet. 24/Online Pharmacy.
  • Buy Cheap order inderal Now Best Drugstore. Discount Online Pharmacy.
  • Buy Cheapest ativan no prescription Now Special Prices For ativan no prescription! Best Internet.
  • Buy Cheapest buspar anxiety Now Top Online Pharmacy Supplier. Best Online.
  • rimonabant acomplia Online Without Prescription Best Prices. Best Online.
  • Buy Cheapest rx drugs without prescription Now Guaranteed Shipping. Cheap Online Pharmacy.
  • Buy Cheap energy diet pill Now Cheap Online Pharmacy. No Prescription Needed.
  • Buy Cheapest buy pain meds online without rx Now Free Viagra Pills! Buy Medications Online.
  • Buy Cheap lasix furosemide Online Low Prices. Drugs, Health And Beauty.
  • Buy Cheapest zovirax Online Guaranteed Shipping. Best Drugstore.
  • Buy Cheap mexican discount drugs Online Pharmacy At The Best Price! Best Drugstore.
  • Buy Cheap clomid ovulation day Now Buy Medications Online. Pharmacy Store.
  • Buy Cheap tablet zolpidem Now Low Prices. All Medications Are Certificated!
  • Buy Cheapest prescription clonazepam Now Low Prices. Pharmacy At The Best Price!
  • Buy Cheap viagra side affects Online Best Drugstore. Cheap Online Pharmacy.
  • Buy Cheap order tofranil Online Best Drugstore. Online Prices For order tofranil!
  • Buy Cheap tips for weight loss Now Discount Online Pharmacy. Pharmacy Store.
  • Buy Cheap ativan information Now Discount Online Pharmacy. WorldWide Shipping.
  • Buy Cheap pharmacies Online WorldWide Shipping. Guaranteed Shipping.
  • Buy Cheapest pain medication online pharmacy Now Low Prices. Online Prices For pain medication online pharmacy!
  • Buy Cheap india pharmacies Now Discount Online Pharmacy. Pharmacy Store.
  • Buy Cheapest cheap 10mg cialis without a prescription Now Cheap Pharmacy Online. Top Online Pharmacy.
  • Buy Cheap cost of viagra Online Cheap Online Pharmacy. Top Online Pharmacy.
  • Buy Cheapest cheapest phentermine online Now Best Online. Cheap Prescription Drugs.
  • Buy Cheap valium and driving Now Guaranteed Shipping. Cheap Pharmacy Online.
  • Buy Cheapest levitra dosing Online Best Drugstore. WorldWide Shipping.
  • Buy Cheap xanax withdrawals Now Cheap Prescription Drugs. Best Internet.
  • Buy Cheap buy prescription diet pills Now Free Viagra Pills! No Prescription Needed.
  • Buy Cheapest free trail of cialis Online Low Prices. Buy Medications Online.
  • Buy Cheap cialis free trials Now The Largest Internet Pharmacy. Best Prices.
  • Buy Cheap cialis buy Now The Largest Internet Pharmacy. Low Prices.
  • online prescription pharmacy Online Without Prescription Best Drugstore. Best Prices.
  • Buy Cheap cheap cialis pillstore Online Online Prices For cheap cialis pillstore! Low Prices.
  • Buy Cheapest impotent tadalafil softtabs Online No Prescription Needed. Best Drugstore.
  • Buy Cheap discount drugstore Online Best Online. Discount Pharmacy Online.
  • Buy Cheap generic cialis absolute lowest price Now 24/Online Pharmacy. Top Online Pharmacy.
  • Buy Cheap alprazolam overdose Online WorldWide Shipping. No Prescription Needed.
  • Buy Cheapest pills zoloft Now We Can Offer You Visit Our Online Pharmacy.
  • Buy order phentermine uk Without Prescription Doctor. Low Prices. Best Online.
  • Buy Cheap phentermine cod delivery Online Drugs, Health And Beauty. Best Prices.
  • Buy Cheap worlds strongest fat burner Now Buy Medications Online. Top Online Pharmacy.