Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLLocationManager alert getting dismissed by itself

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

like image 804
Nikita P Avatar asked Jul 27 '12 13:07

Nikita P


2 Answers

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.

like image 198
Gianluca Tranchedone Avatar answered Sep 26 '22 10:09

Gianluca Tranchedone


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
            }

    }
like image 33
Manikandan Durai Avatar answered Sep 24 '22 10:09

Manikandan Durai