我正在使用swift 2.0而且我坚持这个并且可能有些愚蠢的我不能正确实现..所以,当我关闭手机设置中的位置服务,并打开我的应用程序,告诉用户打开位置服务的提示会不断弹出,并且不允许用户选择任何选项..任何人都知道为什么会发生这种情况?如果已经回答了这个问题,请在我尝试搜索时向我发送链接,但没有得到任何帮助。如果代码的任何部分也需要发布,请告诉我。先感谢您。这就是我实施的方式..
class LocationProcessHandler: NSObject, CLLocationManagerDelegate {
static let sharedInstance = LocationProcessHandler()
let locationManager = CLLocationManager()
func startLocationUpdates() {
NSLog("It entered the start location updates method of the location process handler")
if ((CLLocationManager.locationServicesEnabled() == false) || (CLLocationManager.authorizationStatus() != CLAuthorizationStatus.Denied )) {
NSLog("It Entered to create the managed app feedback ")
let persist = Persistence()
let json: [NSObject : AnyObject] = [
"IsLocationSettingsEnabled" : "\(0)",mdmiosagent_Constants.MESSAGETYPEKEY : mdmiosagent_Constants.LOCATIONMSGTYPEKEY,mdmiosagent_Constants.UDIDKEY : persist.getObject(mdmiosagent_Constants.UDIDKEY),"TimeStamp" : "\(self.toLocalTime())"
]
let userDefaults : NSUserDefaults = NSUserDefaults.standardUserDefaults()
userDefaults.setObject(json, forKey: mdmiosagent_Constants.MANAGED_APP_FEEDBACK)
userDefaults.synchronize()
NSLog("The dict to be sent as managed app feedback is \(json)")
do {
let jsonData : NSData = try NSJSONSerialization.dataWithJSONObject(json, options: NSJSONWritingOptions.PrettyPrinted)
let wrapper = HttpWrapper()
wrapper.silentPostData(serverurl: mdmiosagent_Constants.NATIVE_APP_SERVLET, urldata: jsonData)
} catch {
NSLog("json error")
}
}
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
if #available(iOS 8.0, *) {
if locationManager.respondsToSelector(#selector(CLLocationManager.requestWhenInUseAuthorization)) {
locationManager.requestAlwaysAuthorization()
}
else {
locationManager.startUpdatingLocation()
}
}
NSLog("Started to monitor the significant location Changes")
locationManager.stopMonitoringSignificantLocationChanges()
locationManager.startMonitoringSignificantLocationChanges()
// NSLog("the distance filter of the location manager is \(locationManager.distanceFilter)")
}