0

I have an own website and I want to write an app that loads data (strings/texts) from it to fill a tableview on the iPhone (like a to-do-list). I want to change the content of my app (of the tableview) all the time without doing an update in the App Store. When the app starts it should grab the content from my website...

Should I use FTP for doing things like that or are there better ways to load and manipulate data?

4 Answers 4

6

If the content is in simple text/string then there is no need of FTP (It's useful in case of large file transfer from web to app) then the most suitable methodology is RESTful Services.

RESTful Services are able to GET/POST data in a very easy way. So you can easily transfer data from website to iOS application. And whenever you will change the data it will automatically change the data of iPhone app. So there is no need to change after App Store upload of application.

Hope this helps you !

0

The best way to do is using JSON for passing data between device and server. it is lightweight and very easy to parse.

To communicate over network I would recommend you to you AFNetworking for sending and receiving data(you may also use NSURLConnection but AFNetworking is built over it and is very efficient)

If you are looking for a super fast solution then you may go for PubNub too

-1

For the best developer experience you should use JSON or XML in your REST service.

What I suggest you to do is use CoreData and NSFetchedResultController. This is pretty clear solution.

But for simleproject you may have NSJSONSerialization class or NSXMLParser. In my opinion you should try JSON. The docs are straight forward in this case.

Lets assume you have JSON REST API:

dispatch_queue_t fetchQueue = dispatch_queue_create("nameOfYourQ", NULL);
dispatch_async(fetchQueue, ^{
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://yourlink"]];
    NSArray *arr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    dispatch_async(dispatch_get_main_queue(), ^{
        [yourTableView reloadData];
    });
});

That's it.

4
  • 2
    Not the best solution if you want to handle HTTP errors. using NSURLRequest with NSURLConnection will allow you to better handle any connection or HTTP errors
    – rckoenes
    Aug 26, 2013 at 11:15
  • True. NSURLConnection delegate is more powerful. This solution that i suggest is mostly used by me to set thumbs in tableView. When I working with JSON files i use NSURLConnection. But for beginners this should work perfectly. Note that NSJSONSerialization have pointer to error in last parameter.
    – Jakub
    Aug 26, 2013 at 11:18
  • Also you should always check if there is a network connection available before call any online resource. This is stated in the Apple documentation.
    – rckoenes
    Aug 26, 2013 at 11:21
  • Yes but this is should be checked BEFORE refreshing tableView.. This is not part of this question or answer. and nothing to do with parsing or fetching data mechanism.
    – Jakub
    Aug 26, 2013 at 11:23
-1

A simple solution will be to use JSON over HTTP. To make a more stable solution you could go full RESTful web service. Using HTTP status codes to inform you client application what is going on.

Using AFNetworking will make it very easy to call the web service and parse the JSON response.

4
  • 1
    Bonus: gzip/bzip the JSON data to minimize bandwidth.
    – DarkDust
    Aug 26, 2013 at 11:06
  • 2
    Using an third party framework should NOT be a first suggestion.
    – Jakub
    Aug 26, 2013 at 11:07
  • @rckoenes Becouse this is a very simple problem. I post my suggestion below - using this very powerful framework for this simple operation.
    – Jakub
    Aug 26, 2013 at 11:19
  • "Using AFNetworking will make it very easy to call the web service and parse the JSON response." This is not very complicated in NSJSONSerialization. It's one line of code...
    – Jakub
    Aug 26, 2013 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.