这个想法是当用户从“设置”屏幕切换应用程序的位置服务时,切换应用程序内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")
    }

最佳答案

CLLocationManager可能是您要查找的内容:

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

关于ios - 当用户切换应用的位置服务时,切换应用内GPS UISwitch,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30979761/

10-11 22:57