मैंने एक फ़ंक्शन बनाया है जो स्थान के साथ अनुमति को संभालने का अनुमान लगाता है, ताकि यदि ऐप को स्थान की अनुमति न हो तो ऐप बंद हो जाएगा। हालांकि जब आप ओपन सेटिंग्स दबाते हैं और स्टेटस बार में "ऐप पर वापस" दबाते हैं तो 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)
}
}
इसे ऐपडिडबेकएमएक्टिव में जोड़ने का प्रयास करें। अनुलेख आप एक ऐप को प्रोग्रामिक रूप से बंद नहीं कर सकते हैं जो आप कहते हैं कि आप करना चाहते हैं। अपने कोड में निकास (0) डालने की अनुमति नहीं है। – Gruntcakes
ठीक है, मुझे इसके लिए एक समाधान मिल जाएगा :) लेकिन समस्या –
पर वापस दबाते समय एक विधि को कॉल कर रही है क्या आपने इसे ऐपडिडबैचएक्टिव के साथ आजमाया था? – Gruntcakes