Question

Suppose i have 1000 entries for altitude and longitude in coreData. i want to do reverseGeoCoding for these altitude and longitude and save result back in coreData .Based on below concern i have decided to put reverseGeoCode operation in background

  1. ReverseGeoCode take time when network connection is slow.
  2. we should use only one geocode request per minute.

my question is what is best practice to update coreData in above type of situation? - when application in enter in background ? (not to forget limited backgroundTimeRemaining will be available) - Or on background Thread when application in foreground .

In short for each coordinate i want reverseGeoCoded address. please Give for approach i should follow .

Was it helpful?

Solution

I would suggest a separate ManagedObjectContext reserved for this purpose. This will prevent any locking issues with other CoreData tasks, and allow you to have a MOC for the user's work. Presumably, the user doesn't want to save their work just because an unrelated background task has completed, so they need their own MOC!

Given the relatively slow lookups (1/minute) I'd say to go ahead and saveChanges after each.

You can't do this when the application is in the background; you'll need to cancel any pending reverse geocode requests and resume them when you come back to the foreground. But I would suggest using a background thread when you're foregrounded.

The usual mechanisms apply if you need to use these objects in other MOCs - send a notification or otherwise let them know so they can get a new one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top