Hi all as topic title, my app crash whenever I do the following Steps:
1) Just installed the app (iOS 8 and above only)
2) Click a button that will prompt for Location Service Authorization
3) Deny access
4) An error shows (Correct)
5) Go to Settings -> Application Settings -> Allows Location Service Access
6) Crash! (In my iPhone 5S in iOS 9.2.1)
Here's the code that lead to enabling the Location Service part:
private func initLocationManager() {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
startLocationManger()
}
private func startLocationManger(){
if(autoUpdate){
locationManager.startUpdatingLocation()
}else{
locationManager.startMonitoringSignificantLocationChanges()
}
isRunning = true
}I have no idea whats happening or was there some other code is the culprit??...
func locationManagerStatus(status:NSString){
//Delegate method
LMStatus = status as String
if (status == NSLocalizedString("DN", comment: "Denied access")){
/
LMVerbose = NSLocalizedString("verbose-DN", comment: "You have explicitly denied authorization for this application, or location services are disabled in Settings.")
} else if (status == NSLocalizedString("RT", comment: "Restricted Access")){
/
LMVerbose = NSLocalizedString("verbose-RT", comment: "This application is not authorized to use location services. Due to active restrictions on location services, the user cannot change this status, and may not have personally denied authorization.")
} else if (status == NSLocalizedString("ND", comment: "Not Determined")){
LMVerbose = NSLocalizedString("verbose-ND", comment: "You have not yet made a choice with regards to this application.")
} else if (status == NSLocalizedString("AA", comment: "Allowed access")){
LMVerbose = NSLocalizedString("verbose-AA", comment: "App is Authorized to use location services.")
}
}
func getGPSCoordinates(completion:(ReceivedResult: Bool, ReceivedErrorMessage: String?, latitude: Double?, longitude: Double?) -> Void){
var ReceivedResult = false
var ReceivedErrorMessage = nil as String!
var Receivedlatitude = 0.0
var Receivedlongitude = 0.0
let serviceGroup: dispatch_group_t = dispatch_group_create()
dispatch_group_enter(serviceGroup)
locationManager.startUpdatingLocationWithCompletionHandler { (latitude, longitude, status, verboseMessage, error) -> Void in
ReceivedErrorMessage = error
Receivedlatitude = latitude
Receivedlongitude = longitude
dispatch_group_leave(serviceGroup)
}
dispatch_group_notify(serviceGroup, dispatch_get_main_queue(), {() -> Void in
/
if (ReceivedErrorMessage != nil){
ReceivedResult = false
completion(ReceivedResult: ReceivedResult, ReceivedErrorMessage: ReceivedErrorMessage, latitude: Receivedlatitude, longitude: Receivedlongitude)
} else {
ReceivedResult = true
completion(ReceivedResult: ReceivedResult, ReceivedErrorMessage: ReceivedErrorMessage, latitude: Receivedlatitude, longitude: Receivedlatitude)
}
})
}
func GetCurrentLocationGPS(completion:()){
var receivedStartlat = nil as Double!
var receivedStartlong = nil as Double!
var result = false
var message = nil as String!
let serviceGroup: dispatch_group_t = dispatch_group_create()
dispatch_group_enter(serviceGroup)
if (self.LMStatus == NSLocalizedString("AA", comment: "Allowed access") || self.LMStatus == NSLocalizedString("ND", comment: "Not Determined")){
getGPSCoordinates() { (ReceivedResult: Bool, ReceivedErrorMessage: String?, latitude: Double?, longitude: Double?) in
receivedStartlat = latitude
receivedStartlong = longitude
result = ReceivedResult
message = ReceivedErrorMessage
dispatch_group_leave(serviceGroup)
}
} else {
result = false
message = self.LMVerbose
dispatch_group_leave(serviceGroup)
}
dispatch_group_notify(serviceGroup, dispatch_get_main_queue(), {() -> Void in
self.locationManager.stopUpdatingLocation()
if(result == false){
self.CurrentLocation.text! = message!
} else {
self.Startlat = receivedStartlat
self.Startlong = receivedStartlong
print(self.Startlat)
print(self.Startlong)
}
completion;
})
}LocationManagerStatus is activated as delegate with this function:
internal func locationManager(manager: CLLocationManager,
didChangeAuthorizationStatus status: CLAuthorizationStatus) {
var hasAuthorised = false
let verboseKey = status
switch status {
case CLAuthorizationStatus.Restricted:
locationStatus = NSLocalizedString("RT", comment: "Restricted Access")
break
case CLAuthorizationStatus.Denied:
locationStatus = NSLocalizedString("DN", comment: "Denied access")
break
case CLAuthorizationStatus.NotDetermined:
locationStatus = NSLocalizedString("ND", comment: "Not determined")
break
default:
locationStatus = NSLocalizedString("AA", comment: "Allowed access")
hasAuthorised = true
break
}
verboseMessage = verboseMessageDictionary[verboseKey]!
if (hasAuthorised == true) {
startLocationManger()
}else{
resetLatLon()
if (!locationStatus.isEqualToString(NSLocalizedString("DN", comment: "Denied access"))){
var verbose = ""
if showVerboseMessage {
verbose = verboseMessage
if ((delegate != nil) && (delegate?.respondsToSelector(Selector("locationManagerVerboseMessage:")))!){
delegate?.locationManagerVerboseMessage!(verbose)
}
}
if(completionHandler != nil){
completionHandler?(latitude: latitude, longitude: longitude, status: locationStatus as String, verboseMessage:verbose,error: nil)
}
}
if ((delegate != nil) && (delegate?.respondsToSelector(Selector("locationManagerStatus:")))!){
delegate?.locationManagerStatus!(locationStatus)
}
}
}