我想通过点击按钮启用/禁用用户位置. 在我的AppDelegate中我有这个: let core = CLLocationManager() func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) - Boo
在我的AppDelegate中我有这个:
let core = CLLocationManager() func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { core.requestWhenInUseAuthorization() ...
在我的OptionController中我有这个:
@IBAction func disablePermissionLocation(sender: AnyObject) { }
但是我不知道如果用户在第一次启动应用程序时禁用了该位置,或者如果用户在第一次启动应用程序时启用了位置,则我无法启用位置.
如果你有两个按钮而不是这样: –添加委托 – CLLocationManagerDelegate
//global varible : var locationManager = CLLocationManager() func viewdidLoad(){ locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.requestAlwaysAuthorization() } func enableLocationManager() { locationManager.startUpdatingLocation() } func disableLocationManager() { locationManager.stopUpdatingLocation() }