0

I have an NSThread that checks for new data on the internet. Is it possible to run this thread even when the app is in background by the user in order to check if new data arrived and then show a local notification?

Any help appreciated. Thanks!

jscs
  • 63,694
  • 13
  • 151
  • 195
stefanosn
  • 3,264
  • 10
  • 53
  • 79

3 Answers3

1

Your code can run in the background under certain very well defined conditions; VOIP, GPS, etc...

Beyond that, your code shouldn't be running.

As well, having a background thread that polls for new data is a waste of battery life.

Use a Push notification. This is exactly the kind of notification it is designed for.

bbum
  • 162,346
  • 23
  • 271
  • 359
1

You should read this section of the Apple documention: http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

Basically you can:

  • Get some extra time (10 minutes from what I've seen) to finish up tasks, using beginBackgroundTaskWithExpirationHandler
  • Run certain specific types of tasks in the background (play audio, track location, etc)
  • Use ULNotificationClass to schedule local notifications, but these require user action to 'start' your app back up, they don't directly call your app.
cdemiris99
  • 597
  • 4
  • 6
0

Your thread will run only for limited time after your app enters background. I don't think you can do anything about it.

robbartoszewski
  • 896
  • 6
  • 11
  • I think it is possible to run part of code in the background mode – stefanosn May 09 '13 at 21:51
  • Not the way author of the question wants it. Even if there is a workaround for this, it would be against Apple's rules, so you wouldn't be able to put an application which uses it in AppStore. – robbartoszewski May 09 '13 at 23:27