0

I want to run all that i do in my function :

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
}

in the background. I have my page with many elements and i want that the load of the map don't block the utilisation of the application. When the application did load, the map is initialized and the user must wait few second for the load of the map. I know that we can do something in the background with

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
    [self doWorkInBackground];
});

but i don"t with the locationManager. So i want that the application load without the map, and when the map finish loading it appear on the application. Could you help me ? Thanks.

Undo
  • 25,519
  • 37
  • 106
  • 129
  • Please Go thorough this Link-http://stackoverflow.com/questions/18901583/start-location-manager-in-ios-7-from-background-task – user3182143 Feb 17 '14 at 12:37
  • Please go thorough this link-http://stackoverflow.com/questions/18901583/start-location-manager-in-ios-7-from-background-task – user3182143 Feb 17 '14 at 12:38
  • locationManager:didUpdateToLocation:fromLocation: -> Deprecated in iOS 6.0. Use locationManager:didUpdateLocations: instead. – E. Lüders Feb 17 '14 at 15:57

2 Answers2

0

Yes you should put your code between the async block you posted. That after the map was loaded from within the block you call another method on your view controller to show the map. This you must execute in the main thread otherwise your guy will mess up.

__weak typeof(self) weakSelf = self;    
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // load your map here
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf mapWasLoaded];
        });
 });

__weak is to avoid memory leaks with blocks.

  • Yes i know this method, but i want that the locationManager run in background or in an other thread when it load. For example i have a button which permit to center the map on the user's position and put the annotation around him. Unfortunately it take too much time for load, so i want that it load in background and update the map when it is over. – Gauthier Beignie Feb 18 '14 at 10:17
0

Put this in info.plist file

<key> UIBackgroundModes</key>
    <string>location</string>

For me its work)

Also, very good tutorial! I start with it!

Tutorial

  • I have try, but it doesn't work. Could explain more precisely how you do that ? (for example the "entire" info.plist) maybe i don't do that correctly. – Gauthier Beignie Feb 18 '14 at 10:13
  • in info.plist: key - UIBackgroundModes, type - String, Value - location. Then I set up CLocationManager, set its delegate to self. And when My app goes to background - it start do things which I need. Go to tutorial link. You find here source code and check how it works. In tutorial, you create app which in background mark your route with pins on map. – Vladyslav Semenchenko Feb 18 '14 at 10:30