Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Client/ Server Architecture for an iOS App

I am currently trying to build my own infrastructure so I can understand the client/ server architecture used when connecting an iOS app to a server.

The idea is to create an iPhone application which will recommend restaurants to visit, based on user preferences. Once users sign up to the application and select their favourite food preferences, the application should be able to display and update restaurants which meets their search criteria. In other words, the application will allow users to upload and retrieve data from an online server.

I have very little knowledge about server backend, and was wondering if you could give me some advice as to how I can implement a client - server architecture for my iPhone application?

There will be no more than six clients as this is a small idea I am working on.

As for the server, i would like to implement it using Eclipse (Java EE)

What other things would I need to consider?

Also, How can I have the server send background acknowledgements to say that the data has been received using NSLog?

3 Answers

Hey Brade,

Also a novice here on the back end side of things. I can just tell you what I've learned in the last few months. While there are many options for the backend of an iOS app, what seems to be a very popular method is using MySQL/PHP for the server side, and then using the AFNetworking framework to communicate between the server and app. You can check out a really good tutorial on AFNetworking here to get you started. If the PHP is too confusing, go through the PHP tutorial here on treehouse.

That being said, you should definitely check out some of these new backend as a service (BaaS) products that have come out, in particular Parse. It's an excellent service and is free up to 1 million requests, which would be more than sufficient for 6 clients. I would highly recommend going this route, unless you really want to learn how to do it all yourself. Treehouse has an excellent tutorial on using Parse to create a "snapchat-like" app for messages. Check it out!. This is the path I ultimately chose and so glad I did.

Good luck! We're both in this one together.

+(void)getZona:(NSString *)nameNotification whitApiKey:(NSString*)apiKey
{
 NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
 NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];

    NSString*methodName=@"zones";
    NSString *stringUrl = [NSString stringWithFormat:@"http://kodebinario.com/yourService/%@",methodName];
    NSURL * url = [NSURL URLWithString:stringUrl];
    NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];//
    [request addValue:ENTELACCESSKEY forHTTPHeaderField:@"ENTEL-ACCESS-KEY"];//this is optional
    [request addValue:apiKey forHTTPHeaderField:@"ENTEL-API-KEY"];;//this is optional
    [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];//this is optional
   [request setHTTPMethod:@"GET"];//this is required use POS, PUT or Others

    NSURLSessionDataTask * dataTask = [defaultSession dataTaskWithRequest:request
                                                        completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){
                                                            if(error == nil){
                                                                NSError *jsonError = nil;
                                                                id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonError];

                                                                if ([jsonObject isKindOfClass:[NSArray class]]) {

                                                                    NSArray *jsonArray = (NSArray *)jsonObject;
                                                                    NSLog(@"its an array! %@",jsonArray);

                                                                }
                                                                else {

                                                                    NSDictionary *jsonDictionary = (NSDictionary *)jsonObject;
                                                                    NSLog(@"its probably a dictionary %@",jsonDictionary);

#warning RaΓΊl Quispe: this is my clase Parse
                                                                    [[NSNotificationCenter defaultCenter] postNotificationName:nameNotification object:[Parser  parseZone:jsonDictionary]];//use notification for refresh your views
                                                                }

                                                            }

                                                        }];

    [dataTask resume];
}

alt text

Hi Raul,

Can you please explain to me what you have added. I am Novice student here.

did you create this yourself?

Thank you!

hello?

is very simple, in the image I expose how should be distributed the classes them in the same code I explain how to use NSSURLSession for calling unsynchronized to your web server, as you can see the topic is very extensive, currently I dont control English very well to give you better detailed information but if you has been programming any application, understand the component diagram should be very helpful for you.