CLLocationmanager "locationServicesEnabled" method deprecated in iOS 4?

Jing picture Jing · Aug 23, 2011 · Viewed 19k times · Source

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!

Answer

EmilioPelaez picture EmilioPelaez · Aug 23, 2011

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]