简体   繁体   English

iPhone-在后台检索图像(PUSH)

[英]iPhone - retrieve images in background (PUSH)

I would like to build an app which retrieves images from my server. 我想构建一个从服务器检索图像的应用程序。 My problem is that I want it to work in the background and only when there is a 'new image' to load. 我的问题是我希望它在后台运行并且仅在有“新图像”要加载时才起作用。

It seems like what I need is very similar to PUSH notifications: 似乎我需要的与PUSH通知非常相似:

  • Work in the background 在后台工作
  • Only when there is 'something new' to load. 仅当有“新内容”要加载时。

I guess what I want became possible with the new iOS4. 我想新的iOS4使我想要的成为可能。 Please tell me if this is feasible. 请告诉我这是否可行。 Any links for how to even start thinking about it would be great. 任何甚至可以开始考虑它的链接都很好。 Thanks. 谢谢。

It depends on what background you mean. 这取决于您的背景。

If you mean that your application is running and you have some thread to get the image in the background thread, it is possible. 如果您的意思是您的应用程序正在运行,并且您有一些线程可以在后台线程中获取图像,则有可能。

If you mean that your application is suspended and you still want to use PUSH notification and get the image. 如果您的意思是您的应用程序已暂停,但您仍想使用PUSH通知并获取图像。 I am afraid that it is impossible. 恐怕这是不可能的。 When your application is in the background, it has very limited amount of time that it can run to finish its current task. 当您的应用程序处于后台时,它可以运行的时间非常有限,可以完成当前任务。 When that time is out, your application cannot do anything. 时间到了,您的应用程序将无能为力。

You can receive some push notification and local notification like GPS, server notification when your application is suspended, but you can only receive the server notification and cannot download the new image. 您的应用程序被挂起时,您可以收到一些推送通知和本地通知,例如GPS,服务器通知,但是您只能接收服务器通知,而无法下载新图像。 Here is the instruction from Apple Dev documentation: 这是Apple Dev文档中的说明:

When the operating system delivers a local or push notification and the target application is not running in the foreground, it presents the notification (alert, icon badge number, sound). 当操作系统传递本地或推送通知且目标应用程序未在前台运行时,它将显示通知(警报,图标徽章编号,声音)。 If there is a notification alert and the user taps the action button (or moves the action slider), the application launches and calls the UIApplicationDelegate method application:didFinishLaunchingWithOptions:, passing in the local-notification object or remote-notification payload. 如果有通知警报,并且用户点击操作按钮(或移动操作滑块),则应用程序将启动并调用UIApplicationDelegate方法application:didFinishLaunchingWithOptions:,并传入本地通知对象或远程通知有效内容。 If the application is running in the foreground when the notification is delivered, the application:didReceiveRemoteNotification: or application:didReceiveLocalNotification: method of the application delegate is invoked. 如果在传递通知时应用程序在前台运行,则会调用应用程序委托的application:didReceiveRemoteNotification:或application:didReceiveLocalNotification:方法。

More here 这里更多

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

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