I am calling for current location whenever the user logs in, and at several other places. Whenever I do so, the alert view asking for permission by the user appears for a second or so, and then it gets disappeared. And obviously, I don't get the location. this happens every time I prompt for location. It does not allow the user to click Cancel or OK. Please help
It's likely that you were not retaining the locationManager. As a consequence, when you called [CLLocationManager startUpdatingLocation]
the alert was shown but it disappears as soon as the locationManager is released. It happened to me once when I typed assign instead of strong into the property I had created for my locationManger instance.
Same problem am faced in my project(swift lang).
try this, Declare that CLLocationmanage variable as global variable and call where you want.
ex:
var locManager = CLLocationManager()
override func viewDidLoad()
{
super.viewDidLoad()
let iOS7 = floor(NSFoundationVersionNumber) <= floor(NSFoundationVersionNumber_iOS_7_1)
let iOS8 = floor(NSFoundationVersionNumber) > floor(NSFoundationVersionNumber_iOS_7_1)
locManager.delegate = self
locManager.desiredAccuracy = kCLLocationAccuracyBest
if(iOS8)
{
locManager.requestAlwaysAuthorization()// only support ios 8.0
}
}
Try to move delegate setter method after startUpdatingLocation. It works for me. Example:
CLLocationManager *m = [[CLLocationManager alloc] init];
[m startUpdatingLocation];
m.delegate = self;
Opz, my poor English.
I can't comment his post, so I'm answering here.
Gianluca Tranchedone is right. Im my case, I was retaining the CLLocationManager. BUT: It fires the first callback, right after the AlertView was shown, to tell the delegate that the status is undetermined. I made the mistake to release the instance when whatever callback was received.
This is what the method now looks like and it works:
-(void)locationManager:(CLLocationManager*)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
switch (status) {
case kCLAuthorizationStatusNotDetermined:
break;
default:
_locationManagerForAuthorizationRequest.delegate = nil;
self.locationManagerForAuthorizationRequest = nil;
}
}
© 2022 - 2024 — McMap. All rights reserved.