FabKremer
FabKremer

Reputation: 2179

Background update issue on iOS app

I'm trying to make an "auto-update" process to make the user stay updated every X minutes while the app's awake. What I'm doing it's a background call every X minutes that asks the server if there are updates to make or not.

The thing is that when I make a call and the server returns YES, I've got to to update two things: my local DB and also the user interface (cause there might be changes on the interface too).

What I've got now is a thread problem. If I don't make any drawing while the app's updating I've got no issue, but when I do the app crashes.

Any ideas how could I control that threading issue?

Upvotes: 1

Views: 69

Answers (2)

Jeremie D
Jeremie D

Reputation: 4204

Maybe try running the code on a background thread. one easy way to do this is preformSelectorOnBackgroundThread method...

Upvotes: 0

Jonathan Arbogast
Jonathan Arbogast

Reputation: 9650

I'm assuming you are using CoreData for your database. You need to make sure that any updates you make to the managed object context occur on the thread on which that context was created (typically the main thread).

You also need to make sure that any updates you make to the user interface also occur on the main thread.

Upvotes: 1

Related Questions