0

I have an app that depends on both a network connection and location services in order to be used. Upon launching the app, I would like to check if the user has both of these abilities

  • Network Connection Available
  • Location Services Enabled

How would I script this so that if the user's device does not meet both these criteria, the user is prevented from continuing and is presented with an alert that says they must have these two things to proceed.

I would assume that this goes somewhere in the Application Delegate. Any recommendations would be great! Thank you all!

Brandon
  • 2,163
  • 6
  • 40
  • 64
  • These both question have been asked several times, sepratly: 1. http://stackoverflow.com/questions/1083701/how-to-check-for-an-active-internet-connection-on-iphone-sdk 2. http://stackoverflow.com/questions/4700987/how-to-check-if-location-services-are-enabled-for-a-particular-app-prior-to-ios – rptwsthi Feb 22 '13 at 10:32

4 Answers4

2

For location service you may check

[CLLocationManager locationServicesEnabled]

which returns BOOL value

for internet reachability you may use Reachability class provided by apple http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

use code like this

Reachability *networkReachability = [Reachability reachabilityForInternetConnection];   
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];    
if (networkStatus == NotReachable) {        
    NSLog(@"There IS NO internet connection");        
} else {        
    NSLog(@"There IS internet connection");        
    }        
}
Naimish Karia
  • 346
  • 1
  • 6
1

The CLLocationManager provides class methods to determine the availability of location services as:

+ (BOOL)locationServicesEnabled

+ (CLAuthorizationStatus)authorizationStatus

And for checking the internet connection use the Apple's sample code here. After that check

if ([CLLocationManager locationServicesEnabled] && isInternetAvailable)
{
     //Do your code
}
else
{
    //Alert to show that location manager is disabled or internet is not avaiable.
}
Girish
  • 4,692
  • 4
  • 35
  • 55
1

You can try this for location services:

@property (nonatomic, readonly) CLAuthorizationStatus locationStatus

implement CLLocationManagerDelegate method and track current location authorization status

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
    self.locationStatus = status;
}

if (self.myManager.locationStatus == kCLAuthorizationStatusAuthorized)

as I know [CLLocationManager locationServicesEnabled] not gives needed information.

and use Reachability for checking connections (not sure how to find it, it's a part of ASIHTTPRequest)

[Reachability reachabilityForInternetConnection] isReachable]
[Reachability reachabilityForLocalWiFi] isReachable]
iiFreeman
  • 5,165
  • 2
  • 29
  • 42
0

I hope this will help you..

To check Network Connection Available: Open this apple document link.

To check Location Services Enabled : Open this link

Ashvin
  • 8,227
  • 3
  • 36
  • 53