I need build a client server iphone app. Want to store a database on server and save it too on client's iphone. What strategy and what dbms' and tools i must use for it? AS my database can be enough heavy
This is EASY. If you control both parts of the system.
The magic word here is PLIST's.
IBM have a great example with an iPhone source project and a working google app engine deploy.
http://www.ibm.com/developerworks/web/library/wa-aj-iphone/
Here is some ultra basic code.
// SaveOnline.
NSMutableArray *myArray = [NSMutableArray arrayWithObjects:#"one",#"two",nil];
NSURL *url = [NSURL URLWithString:#"http://www.hurl.ws/api/"];
ok = [myArray writeToURL:url atomically:NO];
if(ok) NSLog(#"saved worked");
You can also load this PLIST from the URL and load it back into your object pretty easily as well. The whole PLIST system is very cool. It is slighly verbose but I would not worry about that as it is ultra flexible and in the long run is going to save you hour and hours of debugging.
I also noticed there a lots of libraries on the server to convert PLISTs into native objects for PHP, Python and assume you can find libraries for Java or .Net.
Dont think about trying to do it in XML your self, its going to get messy ultra quick and yo are going to loose so much time trying to fix it when you dont need.
PLIST's are you friend so use them. John.
For saving to the server, you can try out Parse: http://www.parse.com, they seem to have an easy system for storing data (without you setting up any servers).
On top of that, you can go with persisting the data locally as plist files. Here's a pretty good rundown of the different types of storage options: http://doganberktas.com/2010/10/16/data-storage-alternatives-on-ios-in-a-nutshell/
If you're going for simple, you should just go with storing data in a plist, preferably using the NSCoding protocol, which will allow you to easily store arbitrary objects.
If your database objects are complex you will probably want to use core data and model the objects your own way in the iphone. Of course you will have to sort of translate them when you are going from your service database to storing in core data but that should not be too difficult. If you getting and XML or Json response from your service you should be able to easily parse them and construct your objects over on the iphone and just simply use core data to store them.
The database that you are using on the server side doesn't matter, it's just a black box to the iPhone app. The app can communicate with this server via HTTP using XML, or PLISTs or JSON as John and Daniel recommend.
As far as what's easiest, just go with what server side language you already know. It's probably easiest to run it on something akin to Google app engine, I'd imagine.
bpapa you note "the app can communicate with this server via HTTP using XML", I assume from that you mean web services?
I ask because I'm trying to demystify getting data from the iPhone to a data store such as provided by Google App Engine, and back.
Thanks // :)
P.S.) More to the point of this thread, Google has a great solution for scaleable data store creation without large capital investment. I've been looking at it, Amazon Web Services, and Windows Azure. It seems that, unless you have a heavy reliance on or strong ability in .net, Google's solution makes sense.
Related
There are several apps that I use on my Mac that store their data in core data. I can see the data I want in CoreDataPro. I want that data - specifically I want to send changes in that to some remote end points (such as Zapier, or some other REST service).
I was thinking of piggybacking something like RestKit - such that I provide a configuration file saying where the app is and what end points the data needs sending to. I need only to scrape the data and send to REST, not a two-way sync.
I'd prefer a utility that I could configure rather than having to code a Mac application.
I noted http://nshipster.com/core-data-libraries-and-utilities/ - RestKit still seemed the most capable, but in https://github.com/RestKit/RestKit/issues/1748 I was advised that coredata projects should only be opened by a single application at a time, and really RestKit is designed for baking into the source app (rather than for database scraping and sending).
What approach would you take?
I also noted:
http://www.raywenderlich.com/15916/how-to-synchronize-core-data-with-a-web-service-part-1
Thanks, Martin.
First, Core Data is an object store in memory. What is written to disk from Core Data can be in one of several formats. One of those formats happens to be SQLite. If the application is writing to SQLite then it is possible to sample that same file and push it somewhere else.
However, each application will have its own data structure so you would need to be flexible in the structure you are handling.
RestKit has no value in this situation as you are just translating objects into JSON and pushing them to a server. The built in frameworks do that just fine.
There is no utility to do this at this time. You would need to write it yourself or hire someone to write it.
If I were going to do something like this, I would write it using Core Data itself interrogate the model from the application that wrote the data in the first place and then translate the database into JSON and push it. You won't be able to tell what is new vs. old so the server will need to sort that out.
Another option, since you can't diff anyway, is to just push the sqlite file to the server and let the server parse through it.
Other answers might include:
use a middleware platform e.g. using rssbus.com (only) sqlite connections are free to send the events
as my target system (http://easy-insight.com) actually has a transmitter that sends new records it sees from MySQL abd PostgreSQL, I could https://dba.stackexchange.com/questions/2510/tools-to-migrate-from-sqlite-to-postgresql or use an ETL such as http://www.easyfrom.net (I did ask the vendor for SQLite support a long time ago, but SQLite is just not a priority for them).
I'm wondering whether a good answer (where good excludes Objective-C and includes languages that I do know, such as - to a limited extent - Ruby) is to use MacRuby and its Core Data libraries.
Core Data seemingly can be exposed as an Active Record. https://www.google.com/search?q=macruby+coredata , notably http://www.spacevatican.org/2012/1/26/seeding-coredata-databases-with-ruby/
However, MacRuby seems to have faded - https://github.com/MacRuby/MacRuby/issues/231 - it won't even compile on Mavericks.
I have a rather simple idea for an iPhone app. What I need to accomplish:
Allow login of users (which means I'll have to store usernames, passwords, and other account info).
Allow users to submit strings that other users can view.
Attributes attached to each string that must be tracked (i.e. "votes, views, comments, etc.).
As such, I assume I'll need to start learning about databases and working between a server and client. I've gotten my feet wet in OSX/iOS programming (specifically Objective-C) before. I want to learn how one can accomplish a data-based application and the needs I listed above.
I've done some light research and discovered something called SQLite (free and open-source is always good). Is this the right path to achieve what I want to do? I'm a total "noob" when it comes to this field of server/client/data "stuff".
Your help is greatly appreciated.
SQLLite is more like a local database. Really, the database that you will use is unimportant. It sounds like a project with webservices. Inside your webservices, you might connect to a Microsoft SQL Server or anything you want.
I think you should study how to setup a webservice that can be accessed in your code. Webservices is not an Objective-C topic, it applies to any platform. Your project is more like a web development project.
You can save user's credentials in keychain.
#Kinderchocolate is right about introducing database into your project.
It hears about a app which need transmitting data among clients.It means your need server database and local database.
For server database,I recommend you to use Parse.Parse is a platform which provide a convenient way to use their server database with Objective-c in your app.This tool will save many times and energy(it's not necessary to learn PHP,Apache,Mysql).Parse is not free of course,but it has a free period and enough for you to examine your idea.
Here's Parse!.
For local database,I recommend you to use Core Data,Which is provided by XCode.Core data is so strong to meet your need.You can find a way to use Core Data in many books.
Go try Firebase for database in the cloud. (On the server). In Swift 4 there is complete support for Firebase and SQLite
I'm about to start an iOS project that requires pulling user's data from an SQL Database and viewing it within the App. Before I begin I'm looking for conformation that I'm taking the right (best) route.
My Plan:
App starts on login page (app will display data from another service)
App uses AFNetworking to post request to web service
Web service gets user data from SQL Database and sends back JSON
App uses JSONKit to parse the feed and load into Core-Data
App uses info from core-data to populate UI
Does this seem like an appropriate way to get the info into Core-Data from SQL? Any suggestions for doing things differently?
Thanks.
Are you receiving the response from the web server in JSON? If so, the fact that the server is using an SQL database is immaterial. What you need to know is how to parse JSON for inclusion in a core data store. Cocoa is my Girlfriend has a pretty good tutorial up.
Part 1
Part 2
To answer your comment, here's what I've done.
Display a login screen. The login credentials should be stored in the keychain for security. I've used SSKeychain for this.
To handle sending and receiving data from a web request your best option is to use a pre-built library. I've always used ASIHTTPRequest, but since it is no longer under active development, you should probably look around a bit before you commit to anything. I'm sure there are nicer and cleaner libraries out there.
You need to parse the JSON responses. I'm a fan of JSONKit. It's very fast, very easy to use, very robust.
Pulling data out of the core data store and displaying it in the interface will be no problem for you. If you create a new project in Xcode most of the setup will be done for you.
Now, there are a lot of projects out there that attempt to combine web requests, json parsing and core data loading into one framework. I've tried to use a few of these and haven't had much luck. The ones I've tried haven't been robust and very difficult to debug. Setting up your own request/parse/load code is not difficult at all, just a bit time consuming.
I am sure that there are a lot os ways to make implement this problem. Your solution is one of the popular solutions I guess but you could connect to the DB via a socket and talk with the database directly e.g. Going over a port 80 web site has the advantage that the possibility of some kind of firewall blocking the communication is very low. I would solve this kind of problem the same way I guess.
I'm creating an app for iPhone, and I want it to load data from an external file (from an URL in a server), to display the hints.
I have read several tutorials, but I don't know yet what is more convenient for me:
Do I use CoreData?
Do I create a .sql file and I try to do queries inside the code of my app?
Do I use a .txt file and try to parse it?
Do I use a .xml file?
I have to say I'm quite lost at this point, and I really don't know what would be more effective, easy to write (code). And I don't how to access to a file that is in a server and not in the folder of the app itself.
If your loading data from an external server take a look at Rest Kit. It allows you to map an API to objects that are backed by Core Data. http://restkit.org/
Personally I would use CoreData simply because you get a lot of power out of the box right from Core Data, instead of trying to deal with raw sql queries or parsing data.
Another option if your looking for the simplest way to grab a file from a server and map it to an object is to look at .plists for example:
NSDictionary *data = [dict initWithContentsOfURL:[NSURL URLWithString:#"http://server.com/data.plist"]];
Although be careful with that call though because its not asynchronous, and if the file is large and call is made from the Main thread it will block the application.
The best way to implement database on iPhone SDK is to use CORE Data.
- It prevents you to write long sql scripts to fetch & write data in db.
- Easy Implementation.
- Excellent UI to simulate.
- portable
- Can upgrade later if any enhancement required after some time.
So I would like to suggest you to save your data using Core Data. you need to fetch your data from server & call simple methods to save it into App DB using Core data. You even dont need to do much manipulation into it.
Following are some Nice Links for some tutorials:
http://mobile.tutsplus.com/tutorials/iphone/advanced-restkit-development_iphone-sdk/
http://mobile.tutsplus.com/tutorials/iphone/iphone-core-data/
I am a beginner at both iPhone programming and SQL, yet I have basic knowledge of them.
I am planning to do an application that would plot a graph from data taken from a database of the server of my company. I know how to plot, I know how to extract data from an sql table, but what I don't know is how to access the server.
So do I have to go through some kind of oracle-like application ?
This may seem like a very stupid question because it might not even be possible but any answer will be appreciated.
Thanks !
Go through a web service for example a PHP page that returns JSON (or XML, but JSON is easier to parse).
I can highly recommend this tutorial
Once you have your web service, you can use NSURLRequest/NSURLConnection to download the data and use a JSON framework to parse it. Or, if you're using XML you can use NSXMLParser.
See this apple code for more info on downloading using NSURLConnection.
The best way for this will be, using APIs at server end that handle the client request and perform database interaction, so transfer of data among device and server, take place through XMLs that will be secure as well as fast.
It is definitely possible to contact a server (I can't imagine what would happen without that!). What you are looking for is NSURLConnection. Have a look at the example provided by Apple.