iphone - IOS后台工作

标签 iphone ios multithreading background-process background-thread

我有一个 iPhone 应用程序,例如适用于 iPhone 的 facebook。我的应用程序必须连接我的服务器并定期每两小时读取一次所有消息。我有一个线程来读取所有消息,但是当应用程序终止时,该线程无法工作。线程能否独立于主委托(delegate)运行或如何找到解决此问题的方法?

最佳答案

您不能让您的应用在后台执行操作。有一个 API 可以完成上传照片等任务,但即使这样也会在大约 10 分钟后被终止。

但是Apple Push Notification Service似乎是最适合您问题的解决方案。您的服务器会通知设备发生了一些新事情,并且您会在用户打开应用程序时获取实际消息。

编辑:从 iOS 7 开始,Apple 实现了一项功能,您可以安排正在运行的任务在后台获取数据。这些任务不保证在任何特定时间运行。查看release notes for iOS 7和下面的链接方法:

Apps that regularly update their content by contacting a server can register with the system and be launched periodically to retrieve that content in the background. To register, include the UIBackgroundModes key with the fetch value in your app’s Info.plist file. Then, when your app is launched, call the setMinimumBackgroundFetchInterval: method to determine how often it receives update messages. Finally, you must also implement the application:performFetchWithCompletionHandler: method in your app delegate.

关于iphone - IOS后台工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10881859/

相关文章:

iPhone:UITableView 不刷新

javascript - SPTPersistentCache - 通过唯一 ID 进行视频缓存

c# - 从 C# 中的不同线程启动计时器

python - 如何在pyqt中设置QThread的名称?

ios - NSurlsession 在 Xcode8 中无法使用 swift 2.3

iPhone 声音和延迟

iphone - CSS 过渡 : Fix a div's right edge position while translating the left edge

ios - 如何从 iOS 应用程序共享文本或图像到 Yammer

ios - 从 Firebase 数组中检索数据

android - 只有创建 View 层次结构的原始线程才能触及它的 View 。