iOS: tableview app and database - ios

I want to create a jokes application where jokes can be voted up and down and have ratings.
There is also different categories for the jokes.
My question is how should I store the jokes database?
The jokes database will be growing as application is updated. Do I want to store it on the phone or let the users grab the joke off a database in the web?
If the first option, what is the maximum capacity of text can I store on the iOS app? (In this case, I assume that jokes database will be updated as I update the app)
If the second option, how is this done? I can think of a couple of options, but they aren't really good.
1. store the database on a webpage and just grab it from there (but users cant vote up and down on the jokes)
2. create a mobile website that has all the jokes implemented like a real website, and use webview to show the jokes page to the user. (will probably need a log in system so users cant abuse the votes)
In these two cases, it is unsafe, because someone can just find out where my jokes are hosted by doing a google search and take all my content.
What do you recommend?

The most scalable solution is to build your own backend and fetch data from it on the phone. Application updates should be used for deploying code updates, not content updates. If you want a growing database of jokes to be available to the user, you're going to need a database stored somewhere on the web.
This approach requires you to set up your own webserver with a jokes database (using something like SQL or Postgres). You can use PHP, Ruby on Rails, Django, or other such server-side technologies to process incoming requests and fetch data from the database. The server would then vend this data back to the phone in a network-friendly format like JSON.
On the iPhone side, you can use NSURLRequest and NSURLRequestDelegate to make an asynchronous request to the server. For example, if you wanted to fetch all the jokes from the backend, you might make a GET request to http://www.yoursite.com/jokes. The backend will receive the request, use SQL queries to fetch the jokes, format the data as JSON, and send it back over the network to the phone. The phone can then parse the JSON (there a numerous JSON libraries for Cocoa Touch development) and update the display. To allow users to vote on jokes, you can similarly make POST requests to the backend, which will modify the data in the database.
Here's a simple example of how to work with JSON on the iPhone side: http://mobile.tutsplus.com/tutorials/iphone/iphone-json-twitter-api/

Related

Best way to check for data updates on webserver

I have an application which uses the data from web server. When you first launch the app, it downloads the data and then work with it. But what if the data on web site was changed. How can I know from the application that the data was changed, and if so, what data should I download?
My first idea was each time when you run the application to check the number of entries in the local database on your phone and the number of entries on web server, and if they are not equal, delete all data in local database and then download all data again. But I think that it will take more time than if the application just loads 5-10 needed records instead of all data.
The second idea was when the information on the site changes, website somehow has to inform the application to load some records. But I don’t know if it is possible to do(
Another idea was to compare the id of the last entry in the application database with last id on website. And if they are not equal download the information from the next id.
Are there any suggestions how can I accomplish this?
I am not sure that you have any database or web services but my suggestion is parsing data from the web with JSON or XML.
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/
this class reference is will be clear for you.
Also in my opinion, if you are new in swift and want to choose easy way for this operation search for iOS package managers.
If you want to use a package manager for your project, e.g Pod
https://cocoapods.org/pods/Alamofire
would be a good startig point.
Alamofire is an HTTP networking library written in Swift.
Hope to helped you

client-server fetch large data

I have a application need a list of data, but these data may be very large. If I'm going to show this list of data in client (mobile app), I can't get all of the data from server because the limit space of mobile.
For example, like Facebook app, there are tons of newsfeed in server, and user can only see some of them. If user want to see more, they need to scroll down and fresh. So how to implement something like this in both client and server? (Currently my server is written in ruby on rails, and client is iOS)
And once the client get those data, does it store in memory or in local database? I'm worried about memory limit in mobile phones.
Thanks
On the server-side, you could probably write an API supporting pagination and custom results count, i.e.: myapp.com/api/get?start=0&count=20 to get the first 20 results, and when the user scrolls all the way down your view on the iPhone, fetch the next items, like that: myapp.com/api/get?start=20&count=20.
If you plan your design well, you'll get something very flexible that you'll be able to change later if you realize that 20 results is too much/not enough, etc.
Depending on your app's architecture and the amount of data your app will handle, you might also need to provide API methods based on the last-updated time, to ensure you're not missing data (e.g., if you call your second get?start=20 a few minutes after the first one, the start index might not have the same meaning).
As for storing data locally, it all depends on what you want to achieve. Are you sure you need to save everything the user has downloaded? You could store only the most recently fetched items in a local SQLite database and query them the next time your app starts up, before refreshing the view (I don't know how it is implemented in Facebook's iPhone app but at least it looks like it's done that way).

Handling data request in app, best practice

I am trying to build a iOS based NEWS app. I went through some of the best NEWS app and found out that, when I tap on any menus like Home(for ex.), they request for home data, only once, next time when i tap Home, I think they display cached data because I don't see any sign of request for data, maintaining speed in app.
So how do they maintain the app with recent data, because every time if cached data is displayed, the data may be already changed in server which may not reflect in the app. So what is the best way to handle data request in apps. Is it like I should request data on every tap of menu buttons or should I maintain some timer to request recent data from the server and rest of the time display cached data.
Use CoreData for caching the news and store the timestamp as well and before displaying it to the user, check for the timestamp. If the last updated time is older than 'x' minutes, get the data from server.
Also, you can store the last updated time of the news articles on the server and create an API to just return the article IDs and their timestamps. Then in your app, first query for the time stamps, and fetch only those articles which are missing in your DB or with older timestamps.
The simplest and most popular way is to use Great Http libraries like AFNetwork
or ASIHttp.
This libraries provide support for caching in the most recommended way.
By setting simple cachePolicy you can easily achieve your purpose.
Its not just about caching it can handle many hidden http complexities on its own (cookies,https authentication,Not-Modified http header many more).
I strongly recommend you to use this way as i have already done some of the ios news reading app.

Ruby on Rails, sharing data between applications via a central REST API store

So here is the basic structure I'm proposing:
Data warehouse (for want of a better word)
E-commerce online
Back-end MIS
etc
So the idea is that I have an Order for example. An order can be created via e-commerce site, or via back-end MIS. Either case the order should filter out to e-commerce to show order to user, and vise versa.
There will be other apps in the future.
So the thinking is, to have a central warehouse that wraps this data in a service API, and then the other apps push / pull to it.
Sound OK? I guess the question is syncing the data. When I create an order, do I push the order at create time to the warehouse, or put it to some queue, or is there some other method to keep all these in sync, assuming, near realtime to realtime sync is required.
Assume your REST server is just another data store. How would each client get updates from a plain old database when needed?
If you had each client poll the data store at regular intervals, that would be one solution.

Storing data locally or just using ajax on mobile devices? - appcelerator

Currently I'm building a few mobile apps (currently on iOS but later on Android)that retrieve information via ajax calls (returning JSON) from a Ruby on Rails application. This obviously applies to other applications as well that are using another source to return the JSON data.
The main question is WHEN to store the data and when to just use ajax calls to retrieve it. Currently, my apps do not store a single thing locally and instead require ajax calls for all data. I think for this example we can use the Twitter mobile app, which is one a lot of people are familiar with and has a lot of functionality that I'm wondering how they do it (more logically than technically).
Questions:
1) When you log in the first thing you see is a list of all of the items in your stream. That list is available offline. Does that mean that when you originally signed in, Twitter already went and pulled all of your last X (100?) stream items into a local database and then future views just pull it from there?
2) If you then put your phone on airplane mode (or just shut off mobile data) and click one of those tweets, it opens up the tweet page with all of that data. So now, it looks like they aren't pulling that information in via individually each time you visit a tweet page (which is what my app currently does and takes some time to load that data in and create the views). Does it make sense that they are probably just using the same information that they pulled in when creating your stream items?
3) Users. Is it better practice to (when viewing a users "profile" page for example) store a users data locally and then refresh on future visits, or just do pull in all of the data via ajax each time? In theory each requires an ajax call...
I think those are my main questions for now. If anyone has any thoughts on any of those things (or any other insights into mobile storage) that would be great! If anyone needs screenshots of anything I referenced please let me know and I'd be happy to get those for you.
Currently using:
Titanium Appcelerator for iOS
Ruby on Rails for Backend and remote storage
Ok firstly there is a difference between local storage and device cache.
Mobile phones cache a lot of data so that it doesn't have to be requested each time using up your data plans. Its the same idea when you open a page on safari, go to home screen and go back into safari its still there. This wasn't saved locally its just been cached by IOS.
When you should use local storage is when the data never changes, using twitter as an example like you have, on first start up it downloads your current activity, if one of those contains a link then it will generate a new request, if you have turned off cellular data and still been able to click a link, this is not because twitter has stored it locally but because IOS has cached it temporarily to avoid downloading multiple times. twitter may very well store some of you activity locally, but at least from what I've seen it stores a maximum limit of them starting with most recent, it downloads the rest frequently.
generally speaking if the data is based on the web its fine to use ajax calls, that is what most do, local storage is when the data is only created / viewed on the device (like an app for taking down notes). If you wish to provide local storage so that someone can view there activity offline, great but this is a feature not a requirement.
Most people would only start thinking about this if users frequently request the same data over and over and its not going to change often, then you would need to develop a last modified system, where you send an ajax call to see is there anything new, if not read from local. If the data is dynamic and subject to change often, stick with the ajax calls

Resources