Best way to regularly download data from internet to iPhone app - ios

I have developed an iPhone application that fetches data from internet. I want to check every 30 seconds if there is new data. How do I do that in the best possible way?
The app contains data downloaded from a REST API. The data is light-weight JSON-strings with status updates that will be appended to a UITableView.

You could poll using an NSTimer.

Related

Saving resource on shared framework

I'm making a framework for iOS that collect data from the phone (GPS, WiFi, etc) and sends to a server and notifies the user on events.
My problem is that if two or more apps use the framework on the same device it will consume the battery and I only need to send the data from one app because the collection continues in the background.
Is there any way to know if these multiple apps are running and notify the app that other app is collection and sending the data?
No. The apps are sandboxed and cannot interact.
The framework will have no way of communicating with the other apps unless it sets-up some sort of networking on the client (not advised).
I wouldn't worry about it.
I'll probably look the problem inside out. When I start receiving info on the server from same ip/mac combination simultaneously I'll return a flag to all but one client on that particular device. When my framework receive that kind of flag, it will stop sending data, because someone else is already doing the same.
PS Your framework sounds like creepy spy thing though :)

How does iOS decide whether or not opportunistic background fetch did download anything?

In the Apple documentation about 'Fetching Small Amounts of Content Opportunistically' (https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH4-SW56) the following is written:
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.
How does iOS decide whether there was something downloaded or not, if I am not using NSURLSession? The communication between my app and our backend happens over XMPP. I'm afraid that maybe iOS would think that nothing wasn't downloaded and limit execution time in the future, even if we did retrieve content over the XMPP socket.

Can I make iOS 7 send pictures in the background when network connection is established?

I am building an app for iOS 7 that allows the user to select pictures and upload these to a server. In a perfect world the user would choose the pictures, press upload and be able to close the app.
I looked in to NSURLSession to establish this but it seems to only take a file. Is there any way i can send my NSData like in a NSURLRequest? Also, when not connected to the internet, is there any way i can make the app poll for an internet connection in the background and make it send the pictures when connection is established? I don't think was possible using earlier versions of iOS but iOS 7 seems to have some new options regarding background tasks.
Thanks in advance for any help!
A couple of thoughts:
You are correct that background uploads must use a file. So just save the NSData to a file (e.g. with writeToFile method), and then use that file path.
Regarding checking for Internet connection, the background NSURLSession takes care of that for you, so, no, you don't have to do that.
Regarding background uploads in earlier iOS versions, you could initiate the upload, but explicitly request a little more time to complete this finite-length task while the app runs in the background with UIBackgroundTaskIdentifier. See Executing a Finite-Length Task in the Background discussion in the App States and Multitasking section of the iOS App Programming Guide.
This isn't quite as robust as the new background NSURLSession functionality (which is more clever about applying discretionary logic so your app doesn't significantly adversely affect foreground apps, controlling whether it's permissible to do the upload over cell connection, allowing longer-length requests, working even if your app was terminated (for example, due to memory pressure), etc.). But UIBackgroundTaskIdentifier is a possible solution for iOS versions prior to 7 where you want to give an upload request a chance to complete even though the user has left your app.
Re: your comment about the "GOOD Dynamics SDK", I looked at it quickly. It does allow SDK-based app-to-app document sharing. I don't know if that means it writes a single encrypted on-disk file in the process, or if it uses an encrypted folder to store everything. If you had iOS access to that file, and a way to decrypt it on the server, then you'd have a chance of using the file-based background upload magic.

iOS Offline data buffer

Greeting everyone,
I am looking for a simple way to but my data in a buffer if I ever don't have access to Internet for a certain time.
Lets take a GSP app as an example: I am somewhere with no cell tower but my GPS registers my location. Then when I gain Internet back, it will send these location to the server.
I am currently using restkit to post my objects to the server. When the object is sent to the server, I don't really need it on the phone. So in a way I don't need a 1:1 sync between the iphone and the rest api.
The only idea I have is to have a simple local database (SQLite ?) and monitoring the connection, So I insert in the database when its offline and as soon as the connection is back up, I send the rows and delete them from the local database.
Anyone has a better idea?
Thank you
Jonathan

Best practice to sync webservice with offline storage on iOS

I have been working on a few iOS applications that talk to a REST API on the web server and than sync some data down for offline usage. The app then stores data locally if network connection is not available and than syncs with backend whenever the Internet connection is available.
I am wondering if there is a nice pattern or set of rules or library that can be used. I would rather not code this again and again. I know the business logic / sync logic would be different for each app but the rest of the work (ie. storing it locally, calling REST API) can be abstracted out.
Any ideas?
I use the RestKit framework in my app for the exact scenario you describe. The downloaded data are stored in a Core Data store for offline usage.

Resources