3

I have an application, it will make a reminder to user in specific time. Now, I want to synchronize data from server every 60 minutes (or other duration:1 day, 1 week,... in the future). It must be run even app is already turned off.

I also heard a lot of different answers, but most of them is "iOS does not allow developer makes background thread". Can someone help me to confirm this?

If we can not make background thread, does it have any other solutions to resolve the problem?

I am looking forward to hearing any answers from anyone!

Thanks, Ryan

ryan_le
  • 69
  • 1
  • 8

4 Answers4

1

If you just need to alert the user periodically, local notifications can indeed be scheduled and are fairly easy to implement. If you need to actually update content, look into background fetch: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

Brad Brighton
  • 2,179
  • 1
  • 13
  • 15
1

It's not exactly what you're looking for, but see the App Programming Guide for iOS: Background Execution, notably the Fetching Small Amounts of Content Opportunistically section:

Fetching Small Amounts of Content Opportunistically

Apps that need to check for new content periodically can ask the system to wake them up so that they can initiate a fetch operation for that content. To support this mode, enable the Background fetch option from the Background modes section of the Capabilities tab in your Xcode project. (You can also enable this support by including the UIBackgroundModes key with the fetch value in your app’s Info.plist file.) Enabling this mode is not a guarantee that the system will give your app any time to perform background fetches. The system must balance your app’s need to fetch content with the needs of other apps and the system itself. After assessing that information, the system gives time to apps when there are good opportunities to do so.

When a good opportunity arises, the system wakes or launches your app into the background and calls the app delegate’s application:performFetchWithCompletionHandler: method. Use that method to check for new content and initiate a download operation if content is available. As soon as you finish downloading the new content, you must execute the provided completion handler block, passing a result that indicates whether content was available. Executing this block tells the system that it can move your app back to the suspended state and evaluate its power usage. Apps that download small amounts of content quickly, and accurately reflect when they had content available to download, are more likely to receive execution time in the future than apps that take a long time to download their content or that claim content was available but then do not download anything.

When downloading any content, it is recommended that you use the NSURLSession class to initiate and manage your downloads. For information about how to use this class to manage upload and download tasks, see URL Loading System Programming Guide.

Community
  • 1
  • 1
Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • The thing is, there's absolutely no guarantee of when this will happen. "When a good opportunity arises" could be a week from now. – matt Dec 30 '14 at 04:58
  • Quite right. There isn't a "do network request every 60 minutes" feature, only this opportunistic background fetch. This is Apple's approved mechanism for doing network requests when the app is not active (unless you're one of those special purpose background modes, like VOIP or what have you) or you do push notifications, which is another kettle of fish altogether. – Rob Dec 30 '14 at 05:01
  • Thanks Rob! Your answer is very helpful for me, thanks for explain it in detail. – ryan_le Dec 30 '14 at 06:44
0

you can schedule Local notification to remind user but like in android you can not run background service.

0

You have it backwards. The app, if it is not running, cannot wake up to check the server. But the server can push data down to the app and wake it up - that is what push notifications (remote notifications) are all about:

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/WhatAreRemoteNotif.html#//apple_ref/doc/uid/TP40008194-CH102-SW1

So push at the app when you want to synchronize to it.

matt
  • 515,959
  • 87
  • 875
  • 1,141