CLLocationManager alert getting dismissed by itself
Asked Answered
S

4

11

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

Singlestick answered 27/7, 2012 at 13:37 Comment(2)
got solved by itself. :)Singlestick
I also ran into this problem and can't seem to understand why !?Zoes
M
19

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.

Maryjanemaryjo answered 16/11, 2012 at 14:54 Comment(1)
Why didn't I think of that ? Thanks.Shavonneshaw
I
2

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
            }

    }
Ideation answered 29/4, 2015 at 4:55 Comment(0)
W
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.

Weinshienk answered 11/5, 2015 at 7:51 Comment(0)
F
0

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;
}

}

Flub answered 2/6, 2015 at 10:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.