检测何时按下 "back to app"
Detect when "back to app" is pressed
我已经创建了一个函数,它假设可以处理位置权限,这样如果应用程序没有位置权限,它就会关闭。但是,当您按下打开设置并按下状态栏中的 "back to app" 时,determeinePermission
方法不会再次执行。我尝试将其添加到 viewDidLoad
、viewDidAppear
和 viewWillAppear
。我能做什么?
func determinePermission() {
switch CLLocationManager.authorizationStatus() {
case .Authorized:
if CLLocationManager.locationServicesEnabled() {
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
manager.startUpdatingLocation()
}
case .NotDetermined:
manager.requestWhenInUseAuthorization()
case .AuthorizedWhenInUse, .Restricted, .Denied:
let alertController = UIAlertController(
title: "Background Location Access Disabled",
message: "In order to be notified about adorable kittens near you, please open this app's settings and set location access to 'Always'.",
preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
exit(0)
}
alertController.addAction(cancelAction)
let openAction = UIAlertAction(title: "Open Settings", style: .Default) { (action) in
if let url = NSURL(string:UIApplicationOpenSettingsURLString) {
UIApplication.sharedApplication().openURL(url)
}
}
alertController.addAction(openAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
}
尝试将其添加到 UIApplicationDelegate.applicationDidBecomeActive
。
我已经创建了一个函数,它假设可以处理位置权限,这样如果应用程序没有位置权限,它就会关闭。但是,当您按下打开设置并按下状态栏中的 "back to app" 时,determeinePermission
方法不会再次执行。我尝试将其添加到 viewDidLoad
、viewDidAppear
和 viewWillAppear
。我能做什么?
func determinePermission() {
switch CLLocationManager.authorizationStatus() {
case .Authorized:
if CLLocationManager.locationServicesEnabled() {
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
manager.startUpdatingLocation()
}
case .NotDetermined:
manager.requestWhenInUseAuthorization()
case .AuthorizedWhenInUse, .Restricted, .Denied:
let alertController = UIAlertController(
title: "Background Location Access Disabled",
message: "In order to be notified about adorable kittens near you, please open this app's settings and set location access to 'Always'.",
preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
exit(0)
}
alertController.addAction(cancelAction)
let openAction = UIAlertAction(title: "Open Settings", style: .Default) { (action) in
if let url = NSURL(string:UIApplicationOpenSettingsURLString) {
UIApplication.sharedApplication().openURL(url)
}
}
alertController.addAction(openAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
}
尝试将其添加到 UIApplicationDelegate.applicationDidBecomeActive
。