繁体   English   中英

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

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

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

一个简单的例子:

//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];

除此之外,你可以监控或多或少的准确性,甚至使用wifi /手机信号塔。 请首先阅读示例以获得最佳使用效果。

在iOS 5之前,从第三方应用程序启动手机设置的行为并不一致,但在iOS5中,这种情况有所改善。

如果我们以下面的代码调用startUpdatingLoaction方法,并且如果位置服务关闭,系统警报将弹出,如果我们点击设置按钮,它将导航到手机设置。

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

如果您使用CLLocationManager ,GPS将会打开。

位置管理员将首先通过三角测量获取位置,然后转动GPS以获得更精确的修复。

暂无
暂无

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

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