Consuming RESTful API with RESTframework

As explained in previous post, we’re going to demonstrate how RESTframework handles REST web services. I’ll be consuming a simple Django demo web service created in previous post, so either grab the sources or read the post and build it yourself. Assuming you have this service running on localhost, port 8000, we can continue.

First, download RESTframework from GitHub. With git client, simply type in terminal:

$ git clone git@github.com:ivasic/RESTframework.git

The quickest way to get RESTframework into your project is just including all the files from RFClasses  folder. RF does not have any external dependencies so building shouldn’t be a problem.

RFClasses

RFClasses

Now, we’ll also need JSONKit to parse API response and MBProgressHUD to show some progress. Grab both from GitHub and add to your project.

Fetching objects list

We’ll have 2 view controllers in our demo app. One will be a simple object list and the other one will be, even more simple, view controller for creating a new object. First, we’re going to show how to fetch the object list. We’ll need a GET request to /objects/ URL and we’ll need to parse the JSON array we get in response and show in the table view.

RFRequest* r = [RFRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8000/"] type:RFRequestMethodGet resourcePathComponents:@"objects", nil];
[MBProgressHUD showHUDAddedTo:self.view animated:YES].labelText = NSLocalizedString(@"Loading...", @"");
[RFService execRequest:r completion:^(RFResponse* response) {
	[MBProgressHUD hideHUDForView:self.view animated:YES];
 
	if (response.error) {
		UIAlertView* aiv = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", @"") message:response.error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
		[aiv show];
		return;
	}
 
	self.dataSource = [response.dataValue objectFromJSONData];
	[self.tableView reloadData];
}];

So, what we’re doing in this code snippet is:

  • Creating a GET RFRequest with appropriate URL and resource path
  • Attaching MBProgressHUD to our view to show spinner progress
  • Executing RFRequest and defining the block to execute after RFResponse is received
  • Inside this block, we simply check for errors, parse the response, add to our tableView dataSource and reloading the table
You can see all this in action in the project sample attached to this blog post (at the bottom).

Creating new objects

Our view controller for creating new objects is responsible for creating POST requests to /objects/ URL. Again, very simple, you just need to do this:

RFRequest* r = [RFRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8000/"] type:RFRequestMethodPost resourcePathComponents:@"objects", @"", nil];
 
[r addParam:self.txtName.text forKey:@"name"];
[r addParam:self.lblDate.text forKey:@"date"];
 
[MBProgressHUD showHUDAddedTo:self.view animated:YES].labelText = NSLocalizedString(@"Submitting...", @"");
[RFService execRequest:r completion:^(RFResponse* response) {
	[MBProgressHUD hideHUDForView:self.view animated:YES];
 
	if (response.error) {
		UIAlertView* aiv = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", @"") message:response.error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
		[aiv show];
		return;
	}
 
	UIAlertView* aiv = [[[UIAlertView alloc] initWithTitle:@"Success" message:@"Success" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
	[aiv show];
 
	[self.navigationController popViewControllerAnimated:YES];
}];

Similar to our previous snippet, but this time we also add some parameters to the request – name and date strings.

This is a brief overview with sample Xcode project of how RESTframework consumes RESTful web APIs. Questions welcomed via comments as usual.

 

Download project: RESTframework demo Xcode project download

Worldy Wings: retro air fighter iPhone game

Yesterday I stumbled upon a really nice game called Worldy Winds. It’s a shoot-em-up air fighting game similar to 1942 and 1951 but the gameplay seems better to me. Also, integrated Game Center adds more fun to the game. You have 3 different planes to choose from 5 worlds which is not so good cause you can go through them relatively quickly. But the good side is that you can play all over again to beat your previous score and brag to your friends about it on the Game Center. It integrates GC leaderboards and achievements (a lot of them) so it’s pretty fun to match your score against other players.

All in all, a really nice shooters game if you’re up to it. The only downside is that the graphics, even though beautiful, don’t look so good on iPhone 4 cause the game doesn’t support retina display. I hope the devs include this in the next update or so and make this app even more gorgeous. Also, a bit more levels wouldn’t hurt ;)

The app is available on AppStore for $1.99 at the time of writing.

Unreal Engine 3 on iOS devices

Today I got to try Epic Games ‘Epic Citadel’ free app from Apple’s AppStore which demonstrates the capabilities of Unreal Engine 3 and I must say I’m impressed. This is by far the best 3D environment I’ve seen for mobile devices and also a good sign that the games on iOS devices have a bright future. I took several screenshots posted below so you can enjoy the colors.

The engine features [via Epic Games]:

  • Amazing visuals. “Epic Citadel” pushes the envelope for stunning visuals on iOS devices. Through the latest advances in Unreal Engine 3 technology, the application delivers unrivaled graphics and special effects that immerse players in the kingdom’s grounds.
  • Bump offset mapping. Also known as parallax mapping or relief mapping, bump offset mapping enhances the visual appearance of stone walls and rocks providing intricate textures.
  • Normal mapped architecture. Brings stunning detail to bricks and ground surfaces within the environment.
  • Texture blending with painted weight maps. Refines nuances on roads and terrain, making them rich and lifelike.
  • Global illumination. Unreal Engine 3’s built-in global illumination system, Unreal Lightmass, provides realistic lighting and shadows with minimal development resources.
  • Dynamic specular lighting with texture masks. Helps create authentic cobblestone roads and vivid reflective marble surfaces, while lens flares and light coronas add dramatic emphasis when panning across light sources.
  • Real-time reflections and animation. Environment mapping enables real-time reflections on objects such as the statue inside the cathedral. Dynamic movements of trees and banners are made possible through the use of vertex deformation and skeletal animation.
  • Free tools. Epic’s Unreal Development Kit (UDK), available for free download at http://www.udk.com/download, ships with the same tools and technologies used to create Epic Citadel.

iPhone 4: Unboxing & First Impressions

I know it’s a bit late but got my iPhone 4 today and I’ll share my impressions in this post. There are plenty of posts covering iPhone 4 unboxing, reviews, first impressions, hands-on etc.. These are my own impressions and thoughts probably completely random and not so deep but might be useful as it’s a different perspective.

What’s in the box?

Usual stuff inside, a charger with USB cable, headphones, sim tray pin and obviously the shiny iPhone 4 device. I immediately noticed that I didn’t get the cleaning cloth so that was a disappointment. The cleaning cloth wasn’t in the box with iPhone 3GS too but still I kind of hoped…

iPhone 4 box content

iPhone 4 box content

First impression

Retina display wins big time. Period. I was truly amazed with the display quality and I simply don’t believe the difference between iPhone 4 retina display and older models display. I expected to see the improvement with the screen but I didn’t believe it would be as much better as this. You can see the difference in simple text (mail app for example), the fonts are so crisp and clear and smooth. I’m trying to find some ‘amazing’ words to describe this and risk sounding like Steve, but retina display is just – wow! And yes, I should probably mention that the apps not optimized for it don’t look so good.

Speed, speed, speed and even more speed

This tiny beast powered with Apple’s A4 chip provides as much speed as one would want from a small computer let alone a smartphone. Multitasking is smooth, I haven’t seen a single hickup from the device even when I had more than a dozen apps running in background. The only problems I noticed so far were related to some buggy apps (which I won’t name but, FYI, they are popular) which lag and crash but that’s due to the apps not the iPhone.

As a small test I ran 20+ apps at the same time. Some of them had background multitasking, some didn’t but I was still able to access my huge address book and scroll the list without noticing ANY problems.

Camera(s), 5MP photos, HD videos

Camera is something the community complained about since the very first iPhone 2G. Equipped with 2MP camera, both iPhone 2G and 3G had not so good image quality although daylight photos were pretty much satisfactory for my own taste. iPhone 3GS had the same camera but improved with auto and manual focus. Users wanted more and Steve listened, it was a long wait indeed but we got 5MP camera with LED flash on the back and a front facing VGA camera.

Photo quality is now really awesome and finally you can take beautiful photos with descent resolution. Dark environment photos are also cool now with flash on the back. Front facing camera on iPhone 4 is VGA which is 0.4 megapixels which is not so good but I think good enough for a 2nd camera on the device.

Here are a few pics as a demo taken with iPhone 4.

Conclusion

I haven’t mention FaceTime and some other stuff because I haven’t yet tried it – I was so anxious to put my impressions in here. And yes, my biggest impressions are retina display and speed followed by the camera(s) and then everything else. I think this phone has everything I need as opposed to my previous 3G(s) which lacked features in a few critical areas. Should you get the iPhone 4? Yes. If you have the 3GS you might want to give it a little thought first but if you’re still on iPhone 3G like me – than definitely go for it!

iOS 4.1 due September 8th, solves iPhone 3G performance problems

iOS 4.1 was announced last week with promises to fix incredibly slow UI for iPhone 3G amongst other goodies and fixes. The official release is due September 8th 2010 but the developers have access to GM release for a week now. I have an iPhone 3G so I installed this GM right away to see if it fixes the problems for me and it did. At least a bit.

With 4.0 entering text was slow and painful process, also interacting with the most GUI elements sometimes took a second or even more. Installing 4.1 made UI responsive again, I’m actually able to type SMS and emails without so much frustration. Now the thing I’m worried about is that after almost a week of 4.1, I’m starting to notice some lagging. It’s not nearly as much as I used to have with 4.0 but still, the phone doesn’t appear as fast as it was 5 days ago. It’s probably due to a bunch of stuff I sync’ed with it or at least I hope so.

If you’re an iPhone 3G owner with iOS 4.0 you should most definitely upgrade. And not to forget, Lifehacker uploaded this great video of comparison if you still have doubts whether or not you should upgrade.