#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
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.
You cannot turn location services on from your app if the user has switched them off. You can only check with
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.