Zachary Gay
Zachary Gay

Reputation: 93

Long-Running Upload Task In Background

I am developing an app for iPhone that collects lots of data from vehicles and then uploads it to a remote server. The app itself will be sitting in the vehicle, connected to its battery for power, and collecting data without much user interaction for most of its life. Given that, it is important that these uploads be happening in the background and that the app be "woken up" be the system to do the upload. Also, this is an enterprise app, so the app will NOT need to be put through Apple's approval.

Given these requirements, I had thought that Apple's new iOS 7 background fetch API would be a good solution for my problem. Of course, since I'm not using it entirely as intended, there are some things that could cause some issues for me that I wanted some clarification on.

  1. After watching the WWDC video on the new API, I understand that iOS will attempt to recognize the app's usage patterns and have it woken up only right before it's used. If the app is rarely opened, will that cause it to, eventually, stop doing these background updates?

  2. When I do use this API, the completion handler block I'm given takes a UIBackgroundFetchResult as an argument. If I pass in UIBackgroundFetchResultFailed each time, would that cause iOS to think that I still need that new data and keep waking the app up?

  3. Lastly, since I'm clearly using this API in a different way than it was intended, could someone recommend a better way to do this that would still meet my requirements?

Upvotes: 6

Views: 9366

Answers (4)

Frade
Frade

Reputation: 2988

I know It's been awhile, but just for the record.

I suggest you use AFNetworking, it has background support. Almost everything you need to know is in github page.

For running in background, check this question: afnetworking-background-file-upload. Do not know if the code in the question is working, but the answer might help.

Upvotes: 2

David Pettigrew
David Pettigrew

Reputation: 299

I believe you could use silent push notifications to wake up the app which in turn would do a background upload.

Upvotes: 0

Erben Mo
Erben Mo

Reputation: 3614

IMO, the new ios 7 api is not powerful enough for your app.

  1. background transfer service requires wifi (do you have wifi on the vehicle?) if you don't use background transfer service, you will only have ~30 second to upload your stuff.
  2. background fetch is not called that frequently. From my testing, most of the time fetch happened when user unlocks the phone.

That said, the location service might be a good fit here. any time your vehicle moved to a different cell tower your app can run for about 3 min.

https://developer.apple.com/library/ios/documentation/userexperience/conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html

Upvotes: 0

user523234
user523234

Reputation: 14834

With this given: "app itself will be sitting in the vehicle, connected to its battery for power, and collecting data without much user interaction for most of its life" and "Also, this is an enterprise app, so the app will NOT need to be put through Apple's approval.", why bother with background fetch API at all?

Pick a background mode such as VOIP, and run your task in background mode. Your network connection will stay alive and carrying out any sending/receiving even if screen was locked.

Upvotes: 3

Related Questions