Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLLocationmanager "locationServicesEnabled" method deprecated in iOS 4?

I know the property locationServicesEnabled is deprecated in iOS 4. Instead, I should call locationServicesEnabled

In my app delegate method

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //Some Code Here...
    CLLocationManager *manager = [[CLLocationManager alloc] init];
    if (![manager locationServicesEnabled])
    {   //show an alert
    }
 }   

I called the method, however, Xcode showed me a warning "locationServicesEnabled is deprecated". Anyone knows how to fix this? Because of the warning, if I turned off the location service in system preference, the alert view can't show.

Thanks!

like image 219
Jing Avatar asked Aug 23 '11 04:08

Jing


1 Answers

From the documentation:

locationServicesEnabled: A Boolean value indicating whether location services are enabled on the device. (read-only) (Deprecated in iOS 4.0. Use the locationServicesEnabled class method instead.)

So instead of [manager locationServicesEnabled] you should be using [CLLocationManager locationServicesEnabled]

like image 107
EmilioPelaez Avatar answered Sep 19 '22 15:09

EmilioPelaez