简体   繁体   中英

GPS location is on/off in iphone?

I want to do like, when the app start, app check for iPhone GPS ON or OFF? if GPS off then app quite.

What do you want exactly to know, location service or does user granted access to the location service? If first, than depending on iOS version you can use:

on iOS pre 4.x:

CLLocationManager *testLocationManager = [[CLLocationManager alloc] init];
BOOL servicesEnabled = [testLocationManager locationServicesEnabled];
[testLocationManager release];

on iOS 4.x+:

BOOL servicesEnabled = [CLLocationManager locationServicesEnabled];

If second, than:

on iOS pre 4.x: there is no quick snippet, you have to wait if didFailWithError or didUpdateToLocation will be called and if second, than user granted access

on iOS 4.x+:

BOOL accessGranted = [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized;

And than easily use exit(0) if you option not reached. And yes, try notify user about what you is about to quit the app.

You need to create a CLLocationManager and ask it for locationServicesEnabled . This will tell you if location services are available.

Note however that Apple does not allow apps to quit on their own, the user needs to press the home button instead. If you discover location services are unavailable, you need to tell the user that your app needs them and they should be activated for your app to work properly.

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