简体   繁体   English

我们可以在iPhone中以编程方式打开/关闭GPS吗?

[英]Can we turn on/off the GPS programmatically in iPhone?

我想知道我们可以在iPhone中以编程方式打开/关闭GPS吗?

A simple example: 一个简单的例子:

//Init location manager 

CLLocationManager* locationManager = [ [ CLLocationManager alloc] init];
locationManager.delegate = self; //we must implement the protocol

//Choose your accuracy level

//To turn on gps (if it isn't on already)
[locationManager startUpdatingLocation];

//To turn gps off (if no other apps are listening)
[locationManager stopUpdatingLocation];

There is more than this, and you can monitor more or less accuracy, and even use wifi/ cell towers. 除此之外,你可以监控或多或少的准确性,甚至使用wifi /手机信号塔。 Please read the example first for best usage. 请首先阅读示例以获得最佳使用效果。

Previous to iOS 5 the behavior was not consistent for launch of phone setting from third party application, but in iOS5 this is improved. 在iOS 5之前,从第三方应用程序启动手机设置的行为并不一致,但在iOS5中,这种情况有所改善。

If we are calling startUpdatingLoaction method as below code and if location service is off,the system alert will popup and if we tap setting button,it will navigate to phone setting. 如果我们以下面的代码调用startUpdatingLoaction方法,并且如果位置服务关闭,系统警报将弹出,如果我们点击设置按钮,它将导航到手机设置。

CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];

Well the GPS will be turned on if you use the CLLocationManager . 如果您使用CLLocationManager ,GPS将会打开。

The locationmanager will first start by getting the location via triangulation and then turn the GPS to get a more precise fix. 位置管理员将首先通过三角测量获取位置,然后转动GPS以获得更精确的修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM