简体   繁体   中英

iPhone image upload in background

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?

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.

由于记录失败,使用SDK不允许后台进程。

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM