0
#import "ViewController.h"
#import <NotificationCenter/NotificationCenter.h>
#import <objc/runtime.h>

@interface CLLocationManager

+ (id)sharedManager;
+ (BOOL)locationServicesEnabled;
+ (void)setLocationServicesEnabled:(BOOL)enabled;
+ (BOOL)locationServicesEnabled:(BOOL)arg1;

@end


- (void)viewDidLoad
{
    [super viewDidLoad];
    id CLLocationManager1 = objc_getClass("CLLocationManager");
    self.mySwitch.on = [CLLocationManager1 locationServicesEnabled];//this works fine
}

- (IBAction)doSomeThing:(UISwitch *)sender
{
    id CLLocationManager1 = objc_getClass("CLLocationManager");
    [CLLocationManager1 setLocationServicesEnabled:sender.selected];//this does't work.
    [CLLocationManager1 locationServicesEnabled:sender.selected];
}

1.Get iPhone location in iOS without preference Location Services set to ON

2.IOS8 CLLocationManager.h

I want turn on(off) my iphone6 location services in my app.but this code does't work on IOS8. I don't know why.

Community
  • 1
  • 1
Ryo
  • 1
  • 4

1 Answers1

1

You cannot turn location services on from your app if the user has switched them off. You can only check with

[CLLocationManager locationServicesEnabled]

whether the user has switched them off or not.

CLLocationManager does not have the interface that you show. For the real interface see the Class Reference. You can check that same reference to see how to use the various types of location services.

fishinear
  • 6,101
  • 3
  • 36
  • 84
  • You might want to add that you can start and stop the location manager from getting updates. This will save battery if that's what the op is asking for. – Fogmeister Dec 13 '14 at 12:28
  • 1
    It's a private API.It works on simulator.I develop it for myself. – Ryo Dec 13 '14 at 13:42