当用户切换应用程序的位置服务时,切换应用内GPS UISwitch

时间:2015-06-22 12:14:21

标签: ios swift gps core-location uiswitch

当用户从“设置”屏幕切换应用程序的位置服务时,想法是切换应用内GPS开关。

这是我的模特

func locationManager(manager:CLLocationManager!,didChangeAuthorizationStatus status: CLAuthorizationStatus){
switch status{
case .NotDetermined:
    println("Not Determined!")
    break
case .AuthorizedAlways:                            // It is being authorized always. If this is a security breach or causes
    println("Authorized Always!")
    NSNotificationCenter.defaultCenter().postNotificationName("GpsOn", object: nil)
    self.locationManager.startUpdatingLocation()   // Starts Updating Location in terms of latitude, longitude
    break
case .Denied:
    println("Denied!")
    break
default:
    println("Unhandled authorization status error")
    break
}

}

和ViewController

override func viewDidLoad() {
        super.viewDidLoad()
        self.initMenuWithTitle("Settings")
        settingsArray = ["Filters","Notification","GPS"]
        NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("toggleGps:"), name: "gpsOn", object: self)

    }

func toggleGps(object:AnyObject){
        println("gps on")
    }

1 个答案:

答案 0 :(得分:0)

CLLocationManager可能就是你要找的东西:

func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
  // stuff
}