![](/img/trans.png)
[英]Turn on/off GPS programmatically without prompting the user in iphone
[英]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.