【问题标题】:Toggle in-app GPS UISwitch, when the user toggles the app's location services切换应用内 GPS UISwitch,当用户切换应用的位置服务时
【发布时间】:2015-06-22 12:14:21
【问题描述】:

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

}

还有视图控制器

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")
    }

【问题讨论】:

  • 好主意。你试过什么?
  • @Paulw11 我尝试使用通知中心,但似乎徒劳无功,无法确定何时应该收听位置设置的更改。

标签: ios swift gps core-location uiswitch


【解决方案1】:

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

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

【讨论】:

  • 这几乎就是我在模型中所做的,发布了通知,在视图控制器的 viewDidLoad 中添加了观察者
  • 那你还想做什么?
  • 对不起,如果我在这里含糊不清,当用户从手机的设置屏幕切换应用程序的位置服务时,我需要切换应用程序内 gps 开关。
猜你喜欢
  • 2013-07-19
  • 2013-03-01
  • 2012-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多