Saturday 6 January 2018

iphone - Should an app start location tracking in order to get ANY last known location from CLLocationManager?

Currently, developing an app that needs to get last
location from CLLocationManager (without any regular tracking). It doesn't matter how
old, accurate it is. I don't need and want to start tracking - I just need to just grab
some last location from a cache and that's it. IMHO, CLLocationManager is a shared
component in iOS and if some app uses location tracking then another app should be able
to use the most recent location from CLLocationManager.location. It should be sufficient
just to alloc/init CLLocationManager and grab its location. However it's not. I have
tested on iPhone4 - started google maps, saw my current location, then went to my app,
but after [[CLLocationManager alloc] init] location property is nil.



UPDATE: tried [locationManager
startUpdatingLocation]; and [locationManager stopUpdatingLocation]; but the result is
the same. I guess, the only solution is to start regular
tracking?



UPDATE2: Strange but there's no alert
with "The app wants to use location services" after alloc/init of CLLocationManager.
Here's my code
fragment:



CLLocationManager
*locationManager = [[CLLocationManager alloc]
init];


[locationManager
startUpdatingLocation];
[locationManager
stopUpdatingLocation];
NSLog(@"%@", locationManager.location); //prints
nil

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...