Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

iPhone and Rails integration


Published on

ObjectiveResource is an Objective-C port of Ruby on Rails' ActiveResource. It provides a way to serialize objects to and from Rails' standard RESTful web-services (via XML or JSON) and handles much of the complexity involved with invoking web-services of any language from the iPhone.
This talk shows you how easy it is to create a 2-way communication channel between a very basic Rails application and an iPhone app.

Published in: Technology, News & Politics

iPhone and Rails integration

  1. 1. iP[od|hone|ad] & the tubes Paul Ardeleanu
  2. 2. Why? 75m devices to date (iPhone + iPod touch) 140k iPhone apps available 3bn downloads in 18 months Average user spends $8/month There will be a second gold rush Your MD will love it
  3. 3. No really, why? Objects are everywhere (NSObject) MVC framework Extremely consistent API Extremely good documentation Easy to pick up
  4. 4. Challenges Methods syntax Selectors Memory management (no garbage collection) Autorelease Delegates
  5. 5. Exchange data NSURLRequest XML NSURLConnection JSON NSString *url = [NSString stringWithFormat:@"%@%@", @"https://websi.te/contacts.xml", self.path]; NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]; NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data - (void)connectionDidFinishLoading:(NSURLConnection *)connection - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
  6. 6. Objective Resource Objective-C port of Ruby on Rails' ActiveResource
  7. 7. Demo
  8. 8. Configuration //Set the address of the rails site. The trailing slash is required [ObjectiveResourceConfig setSite:@"http://localhost:3000/"]; //Set the username and password to be used for the remote site [ObjectiveResourceConfig setUser:@"remoteResourceUserName"]; [ObjectiveResourceConfig setPassword:@"remoteResourcePassword"]; [ObjectiveResourceConfig setResponseType:XmlResponse];
  9. 9. Model @interface Conference : NSObject { NSString *conferenceId; NSString *name; NSString *location; NSString *startDate; } @property (nonatomic , copy) NSString *conferenceId; @property (nonatomic , copy) NSString *name; @property (nonatomic , copy) NSString *location; @property (nonatomic , copy) NSString *startDate; @end
  10. 10. Model @implementation Conference @synthesize conferenceId; @synthesize name; @synthesize location; @synthesize startDate; - (void)dealloc { [conferenceId release]; [name release]; [location release]; [startDate release]; [super dealloc]; } @end
  11. 11. Remote methods [Conference findAllRemote]; Conference *conf = [[Conference alloc] init]; [conf saveRemote]; [conf findRemote:45]; [conf updateRemote]; [conf destroyRemote];
  12. 12. Thank you! Paul Ardeleanu demo projects available for download at