如何在IOS8上使用objective-c打开/关闭位置服务

时间:2014-12-13 12:12:41

标签: objective-c iphone gps ios8 location-services

#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

我想在我的应用中打开(关闭)我的iphone6位置服务。但是这段代码不适用于IOS8。我没有 知道原因。

1 个答案:

答案 0 :(得分:1)

如果用户已将其关闭,则无法从应用中启用位置服务。您只能查看

[CLLocationManager locationServicesEnabled]

用户是否已将其关闭。

CLLocationManager没有您显示的界面。对于真实界面,请参阅Class Reference。您可以检查相同的参考,以了解如何使用各种类型的位置服务。