简体   繁体   English

iPhone图像上传背景

[英]iPhone image upload in background

I'm writing an app with an image upload feature. 我正在编写一个带有图片上传功能的应用。 Right now I'm using NSURL POST like: 125306 . 现在我正在使用NSURL POST,如: 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? 1)当应用程序不再在前台时,一种使这些上传线程持续存在的方法?

2) an iPhone OS service that will accept requests to queue a job and run it in a mode managed by the OS? 2)一个iPhone OS服务,它将接受排队作业的请求并以OS管理的模式运行它?

EDIT: This is an old answer from 2009. Current iOS (2016) has background URL tasks. 编辑:这是2009年的旧答案。目前的iOS(2016)有后台URL任务。 See NSURLSessionUploadTask. 请参阅NSURLSessionUploadTask。

Original answer follows: 原始答案如下:

You aren't allowed to run in the background on an iPhone (as per Apple's Guidelines). 您不能在iPhone的后台运行(根据Apple的指南)。 Your app will be rejected from the AppStore if you do. 如果您这样做,您的应用将被拒绝从AppStore。

由于记录失败,使用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. 更好的解决方案是调整大小,以及提供当前上载百分比的进度指示器 - 但这涉及一些自定义的低级HTTP代码。

After app suspending you only have ~10 mins to do the job. 应用程序暂停后,您只需约10分钟即可完成工作。 You should make a background process thread when app is suspended. 应用程序暂停时,您应该创建后台进程线程。 And you have no garanties that os will keep app alive. 并且你没有任何保证,os将保持app活着。 It depends on process complexity. 这取决于流程的复杂性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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