2

I'm writing an app with an image upload feature. Right now I'm using NSURL POST like: 125306.

When the app is closed as far as I can tell all of the uploads abort and the threads die. Is there

1) a way to make these upload threads persist when the app is no longer in the foreground?

2) an iPhone OS service that will accept requests to queue a job and run it in a mode managed by the OS?

Community
  • 1
  • 1
Martin Redmond
  • 13,366
  • 6
  • 36
  • 32

4 Answers4

9

EDIT: This is an old answer from 2009. Current iOS (2016) has background URL tasks. See NSURLSessionUploadTask.

Original answer follows:

You aren't allowed to run in the background on an iPhone (as per Apple's Guidelines). Your app will be rejected from the AppStore if you do.

Lou Franco
  • 87,846
  • 14
  • 132
  • 192
  • To sound more correct, its not that we are not allowed to (as in but we can if we want) but we simply cant even if we want. It is just not possible to develop an app for iPhone which would run in background. – Chintan Patel Oct 31 '09 at 05:04
  • I'm not sure that's true. Email and Safari seem to do things in the background (email definitely continues to download my messages). There are probably non-public API's to do it. However, if you call them, you will be rejected. – Lou Franco Oct 31 '09 at 17:00
4

As has been failry well documented, no background processes are allowed using the SDK.

August
  • 12,139
  • 3
  • 29
  • 30
1

As noted, you cannot have a background process - a good compromise would be to resize the photo down to a size that could be transferred in a reasonable amount of time (user configurable would be best), and display an activity indicator of some kind so the user would know the upload was in progress.

An even better solution would be the resize, along with a progress indicator giving the percentage currently uploaded - but that involves some custom low-level HTTP code.

Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150
0

After app suspending you only have ~10 mins to do the job. You should make a background process thread when app is suspended. And you have no garanties that os will keep app alive. It depends on process complexity.

Tim Kozak
  • 4,026
  • 39
  • 44