Correct way to poll server in background

后端 未结 2 456
误落风尘
误落风尘 2021-01-31 05:49

Assuming this is possible, I would like my iOS application, when backgrounded, to poll a server (i.e. essentially, retrieve the contents of a URL every 30 minutes and notify the

相关标签:
2条回答
  • 2021-01-31 06:14

    What you want to do, is not covered under the multitasking features of iOS4. There are only a few types of applications allowed to run in the background for long periods of time (more than 10 minutes), and generic networking applications aren't one of them.

    However, all is not lost. What you can do, and what I believe you should do is to use push notifications. On your server, you link up with apple's push notification service, the user registers for push notifications, and you either know what "interesting data" is, or they tell you. When that data is available, you send it to the user immediately via a push notification.

    It provides a nicer user experience, and your app doesn't need to be running in the background. iOS will handle delivery of the push notification. If they swipe to unlock the phone when they get the notification, your app will open up, and at which time, you can load that useful information in your app.

    Your method 1 won't work long term, even if you do manage to pause input for a while, and this is why: Launching a background task runs a task for NO MORE than 10 minutes, unless you are one of the three types of applications that is allowed to stay running. After 10 minutes, the OS will suspend you.

    Your method 2 won't work at all. All local notifications present an alert view to users.

    0 讨论(0)
  • 2021-01-31 06:15

    Assuming this is possible...

    Unfortunately that's a faulty assumption(!).

    You can't do it using the "multi tasking" on the iPhone, as it only allows certain kinds of background processing (GPS, VoIP, music). To do what you want you'll need to do the work on a server and use push notifications.

    0 讨论(0)
提交回复
热议问题