1

My app has Background App Refresh when it receives a Push Notification where it fetches data from the server and stores using Core Data, now I need to process the data when the App is becomes active again. So, I tried the fetch query when -(void)applicationDidBecomeActive:(UIApplication *)application is called to get the data.

But, if I directly query the tables immediately, the query returns 0 objects if the App is in stopped state. I guess the Core Data connectors are not prepared by the time I call the query. I am sure that the data is saved in the tables as if I make the query using dispatch_after 2 secs , I get the complete data.

I do not want to make the Query on viewDidLoad/viewDidAppear cause, it is not necessary that these will be called when the app goes becomes active from non active state.

3
  • 1
    How do you initialise Core Data? CD should be available immediately, unless you assigned the adding of the persistent store (NSPersistentStore) to the persistent store coordinator (NSPersistentStoreCoordinator) to a background queue. In that case initialisation of Core Data may finish later than the point at which you carry out your fetch. But then again, your NSManagedObjectContext would still be nil and it should give an error.
    – Arjan
    Feb 25, 2016 at 21:40
  • What is the data protection for the app? The SQLite file may still be encrypted and you need to wait until it's available...
    – Wain
    Feb 25, 2016 at 21:42
  • So, I have not enabled any sort of data encryption on my end(though I am not aware if iOS does it by itself). In any case is there a callback or a notification so that I know that the SQLite is available to be read? Current logic that I went with is to simply wait for 2 secs, which seems wrong
    – rahulg
    Feb 25, 2016 at 21:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.