要取得位置,就需要使用GPS,iOS5 以上的版本當使用 startUpdatingLocation 時會自動詢問是否開啟GPS唷。

(1)增加CoreLocation.framework 

螢幕快照 2016-09-06 下午4.42.02.png

(2)在ViewController 內加入

           #import <CoreLocation/CoreLocation.h>

(3) 加入init 的location manager related code.

//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];
arrow
arrow
    文章標籤
    iOS GPS CLLocationManager
    全站熱搜

    lionlionchopper 發表在 痞客邦 留言(0) 人氣()