Adrien G
Adrien G

Reputation: 228

[iOS][Background] updating map pins | drawing lines

Hy :)

I am trying to update in background the position of the device (iPhone) and it works with the simulator http://grab.by/meLq (the annotations are only added in Background).

But when I am testing with my iPhone it does not work, I have got a line between the last position (before being in background) and the position when the becomes active.

What about the coding ?

I made a test of making a list when the app is in background and when the application becomes active again I load the list of positions recorded. (work with the simulator)

    - (void)handleAddLocations {
        NSLog(@"%s | %@", __PRETTY_FUNCTION__, self.locationBackgroundList);

        if ([self.locationBackgroundList count] > 0) {
            for (CLLocation *backgroundLocation in self.locationBackgroundList) {

                if (YES){
                    LocAnnotation* annotation = [[LocAnnotation alloc] initWithCoordinate:backgroundLocation.coordinate];
                    NSLog(@"%s %@", __PRETTY_FUNCTION__, [annotation description]);
                    [self.mapView addAnnotation:annotation];
            }

        MKUserLocation *userLocation = [[MKUserLocation alloc] init];
        [userLocation setCoordinate:backgroundLocation.coordinate];

        [self mapView:self.mapView didUpdateUserLocation:userLocation];

         }
        [self.mapView updateConstraints];

        [self.locationBackgroundList removeAllObjects];
        self.locationBackgroundList = [[NSMutableArray alloc] init];
      }
  }

Thanks for helping ;)

Upvotes: 0

Views: 273

Answers (1)

Divyam shukla
Divyam shukla

Reputation: 2048

Its a better option to add the annotation by creating a list in of locations in background.This is not possible to manage uielements when the app is in background.For this you should add all the positions in array while yous app is in background.

Upvotes: 1

Related Questions