在后台运行无效操作?
我有一个简单的应用程序,允许人们将图片上传到服务器。由于某种原因,在上传每个文件时,应用程序会冻结,并且不允许您对其执行任何其他操作。
有没有办法在后台运行它?
谢谢。
I have a simple app that allows people to upload pictures to a server. For some reason, while it's uploading each file the app freezes and won't allow you to do anything else on it.
Is there anyway to run it in the background?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 iOS 或 Mac OS 上,您可以使用 NSThread, NSOperation,或 libDispatch(在 iOS 4 或 Mac OS 10.6 上)。还有 pthreads,不过我不确定 iOS 上是否可用。有关更多信息,您可能需要查看这个其他问题(其中针对 iOS 应用程序,但我认为同样适用于 Mac OS)。
编辑(回复评论):最简单的方法(或者我猜我更喜欢的方法,也许它不是那么简单,甚至不是一个好主意)可能是使用 libDispatch 和类似的东西:
无论这是否是 正确的做事方式,我不知道。您必须为此做进一步的研究(再次参考我上面指出的另一个问题)。另外,我不确定该代码是否完全正确,因为我只是在文本编辑器中编写了它,而没有通过编译器运行它。
On either iOS or Mac OS, you could handle that in a separate thread using NSThread, NSOperation, or libDispatch (on iOS 4 or Mac OS 10.6). There's also pthreads, though I'm not sure whether that's available on iOS. For more information, you might want to check this other question (which is aimed at iOS apps, but I think could apply equally well to Mac OS).
Edit (response to comment): The simplest way (or I guess my preferred way, maybe it's not so simple, or even a good idea) would probably be to use libDispatch and something like this:
Whether or not this is a correct way to do things, I don't know. You would have to do further research for that (again, refer to the other question I pointed out above). Also, I'm not sure if that code is entirely correct, since I just wrote it up in a text editor without running it through a compiler.