【问题标题】:How to turn on/off location services with objective-c on IOS8如何在IOS8上使用objective-c打开/关闭定位服务
【发布时间】:2014-12-13 12:12:41
【问题描述】:
#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 上不起作用。我不 知道为什么。

【问题讨论】:

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


    【解决方案1】:

    如果用户关闭了定位服务,您将无法从您的应用开启定位服务。你只能用

    [CLLocationManager locationServicesEnabled]
    

    用户是否已将其关闭。

    CLLocationManager 没有您显示的界面。真实界面见Class Reference。您可以查看相同的参考资料,了解如何使用各种类型的定位服务。

    【讨论】:

    • 您可能需要补充一点,您可以启动和停止位置管理器获取更新。如果这是操作人员要求的,这将节省电池电量。
    • 这是一个私有 API。它适用于模拟器。我为自己开发。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-26
    • 1970-01-01
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多