1. Rails as iOS Application Backend
Shanghai On Rails – Saturday 21st, 2011
2. iOS Applications
• Which website doesn’t have an iPhone application ?
• iPhone application add a mobility aspect to your web
application - GPS, on-the-go, etc.
• Push notifications brings retention
3. As a Rails Developer,
why do I care about mobile?
18. Authentication
• Havethe iPhone behaves
as a web browser.
• Sending cookies with
every request
• Persisting cookies on the
iPhone
• Good news for your Railer:
nothing new!
19. Authentication
• Havethe iPhone behaves
as a web browser.
• Sending cookies with authlogic
every request devise
....
• Persisting cookies on the
iPhone
• Good news for your Railer:
nothing new!
20. Authentication
• Havethe iPhone behaves
as a web browser.
• Sending cookies with authlogic
every request devise
....
• Persisting cookies on the Cookies!
iPhone
• Good news for your Railer:
nothing new!
21. Authentication
• Havethe iPhone behaves
as a web browser.
• Sending cookies with authlogic
every request devise
....
• Persisting cookies on the Cookies!
iPhone
• Good news for your Railer:
nothing new!
23. iOS side
Application code
• Not as easy.
• NSURLConnection is JSONRequest
low level
NSURLConnection
• JSONRequest provides
you a higher level iOS Network Socket
interface
24. JSONRequest
➊ Initiate HTTP request to /inventory
➋ Handle networking, cookies, redirections and errors
➌ Parse HTTP Response as JSON
42. Write your own .to_json
1k byte
> puts Counter.all.map(&:to_json).to_json
[{"name":"Mend","strength":11,"id":12,"icon":"/system/pictures/21/large/Glass-2.png?1299820062"},{"name":"Radiate","strength":
11,"id":13,"icon":"/system/pictures/10/large/potion-1.png?1299786958"},{"name":"Float","strength":31,"id":10,"icon":"/system/
pictures/31/large/Untitled-1.png?1299820281"},{"name":"Shine","strength":31,"id":11,"icon":"/system/pictures/12/large/
point-3.png?1299787038"},{"name":"Pure","strength":51,"id":9,"icon":"/system/pictures/30/large/Umbrella-3.png?1299820262"},
{"name":"Bounce","strength":51,"id":1,"icon":"/system/pictures/8/large/shield-2.png?1299786772"},{"name":"Reflect","strength":
71,"id":6,"icon":"/system/pictures/9/large/shield-3.png?1299786787"},{"name":"Detect","strength":81,"id":7,"icon":"/system/
pictures/26/large/Shield-1.png?1299820172"},{"name":"Healer","strength":81,"id":8,"icon":"/system/pictures/34/large/Vest-3.png?
1299820340"},{"name":"Counter","strength":101,"id":14,"icon":"/system/pictures/28/large/Shield-3.png?1299820222"},
{"name":"Return","strength":151,"id":5,"icon":"/system/pictures/20/large/Glass-1.png?1299820042"}]
By writing your own to_json method, you not only
optimize the size of the body but also you can be
much more specific and prepare your own data
53. Push Notification
• Rake task triggered by crontab
• Resque scheduler
• Ifyou want to schedule a Rake task every minute or even
every 5 minutes, you will consume a lot of resources on
your server to boot up the Rails environment.
• Be careful about 256 bytes size limit!
55. Thank you
• maxime@ekohe.com
• Thanksto maverick@ekohe.com for his contribution on
the JSONRequest / Model ORM
• Thanks
to jimmy@ekohe.com for writing an awesome
backend for Breeze Living
Editor's Notes
\n
\n
\n
For some sites, the mobile provides instant information: BBC, NyTimes, Twitter\nFor some others, they are just an extension on the platform: Google, Youtube\n\nInstagram, Foursquare very integrated to the mobile \n\n
For some sites, the mobile provides instant information: BBC, NyTimes, Twitter\nFor some others, they are just an extension on the platform: Google, Youtube\n\nInstagram, Foursquare very integrated to the mobile \n\n
For some sites, the mobile provides instant information: BBC, NyTimes, Twitter\nFor some others, they are just an extension on the platform: Google, Youtube\n\nInstagram, Foursquare very integrated to the mobile \n\n
For some sites, the mobile provides instant information: BBC, NyTimes, Twitter\nFor some others, they are just an extension on the platform: Google, Youtube\n\nInstagram, Foursquare very integrated to the mobile \n\n
For some sites, the mobile provides instant information: BBC, NyTimes, Twitter\nFor some others, they are just an extension on the platform: Google, Youtube\n\nInstagram, Foursquare very integrated to the mobile \n\n
For some sites, the mobile provides instant information: BBC, NyTimes, Twitter\nFor some others, they are just an extension on the platform: Google, Youtube\n\nInstagram, Foursquare very integrated to the mobile \n\n
For some sites, the mobile provides instant information: BBC, NyTimes, Twitter\nFor some others, they are just an extension on the platform: Google, Youtube\n\nInstagram, Foursquare very integrated to the mobile \n\n
For some sites, the mobile provides instant information: BBC, NyTimes, Twitter\nFor some others, they are just an extension on the platform: Google, Youtube\n\nInstagram, Foursquare very integrated to the mobile \n\n