Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8405473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:51:41+00:00 2026-06-09T22:51:41+00:00

I am trying to set up an app so that there is a background

  • 0

I am trying to set up an app so that there is a background task where the locationManager receives updates that are then stored using Core Data. Here is the code I am using to run the locationManager as a background task:

(void)viewDidLoad
{
    [super viewDidLoad];

timerAndMap = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
            [self endDate];
     }];

        if(nil == locationManager) {
        locationManager = [[CLLocationManager alloc] init];
        }

    locationManager.delegate = self;
    locationManager.distanceFilter = 500;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];

  [[UIApplication sharedApplication] endBackgroundTask:timerAndMap];

}

However, the problem I am having is figuring out how to make the delegate methods part of the background thread. When the locationManager calls didUpdateToLocation I want to save the longitude, latitude, and date of the new location as attributes of an entity in a temporary managedObjectContext that is then merged with my established ManagedObjectContext on the main thread (as to my understanding while the app is running in the background new Core Data entities cannot be stored to my main thread ManagedObjectContext).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:51:42+00:00Added an answer on June 9, 2026 at 10:51 pm

    Locations are updated every second or so, create a NSMutableArray with the coordinates, keep a list of the coordinates, and when it reaches a point, create an NSArray with the coordinates from the mutable array, clear the NSMutableArray, pass the NSArray instance to the background thread, and perform the save.

    Edit: based on the new information: CLLocationManager’s method are asynchronous. What you can do is, if this is what you are trying to accomplish, to dispatch a background block and create your entity within the block on your delegate callback. You can even manage your own own serial dispatch_queue to do this.

    Take into consideration thou, that just because you are doing something it the background that does not make it efficient. You will still be calling save every time you get a new location (which could be every 1-2 seconds). Writing into the persistent store is expensive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an android app that has the following: Theme set
I'm trying to create a WinForms app that takes a screenshot on a set
I'm having an issue using a new WPF app that is trying to display
Im trying to set up my app to work with authlogic.. the thing is,
Trying to set up Cancan within an app of mine and having trouble with
I am trying to set a cookie in my Google App Engine page: self.response.headers.add_header('Set-Cookie','CookieName=1234;
I am trying to set the scaleMode on my AIR app. which is set
I am trying to set up a Sinatra based Ruby app to connect to
We're trying to set up Spring-Test-MVC for our Spring-MVC web app. We started out
I'm trying to set up a date of birth helper in my Rails app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.