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.在 iOS 中获取 iPhone 位置,无需将“位置服务”设置为“开”

2.IOS8 CLLocationManager.h

我想在我的应用程序中打开(关闭)我的 iphone6 定位服务。但此代码在 IOS8 上不起作用。我不知道为什么。

4

1 回答 1

1

如果用户已将其关闭,则您无法从您的应用中打开定位服务。你只能检查

[CLLocationManager locationServicesEnabled]

用户是否已将其关闭。

CLLocationManager没有你显示的界面。对于真正的接口,请参阅类参考。您可以查看相同的参考资料,了解如何使用各种类型的定位服务。

于 2014-12-13T12:24:47.543 回答