ebook img

iOS on Rails. The reference for writing superb iOS apps with Ruby on Rails backends PDF

132 Pages·2014·2.06 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview iOS on Rails. The reference for writing superb iOS apps with Ruby on Rails backends

iOS Rails The reference for writing superb iOS apps with Ruby on Rails backends. iOS on Rails (Beta) thoughtbot JessieYoung DianaZmuda October24,2014 Contents Introduction iv I BuildingtheHumonRailsApp 1 Introductiontoourexampleapplicationandsetup 2 CreatingaGETrequest 8 CreatingaPOSTrequest 16 CreatingaPATCHrequest 27 CreatingageocodedGETrequest 34 II BuildingtheHumoniOSApp 42 Introduction 43 ANewXcodeProject 44 AlphaandBetaSchemes 45 i CONTENTS ii ManagingDependencies 50 TheMobileApp’sSkeleton 53 TheMapViewController 54 TheAddanEventViewController 59 ARailsAPIClientWithNSURLSession 63 ARailsAPIClientWithAFNetworking 68 TheUserObject 71 PostingaUserWithNSURLSession 75 PostingaUserWithAFNetworking 81 MakingthePOSTUserRequest 85 TheEventObject 87 PostinganEventWithNSURLSession 93 PostinganEventWithAFNetworking 96 MakingthePOSTEventRequest 98 PostingwiththeEventViewController 102 GettingEventsWithNSURLSession 108 GettingEventsWithAFNetworking 112 CONTENTS iii DisplayingEventsontheMap 115 ViewingIndividualEvents 121 FinishingTouches 124 Introduction Whythisbook? TherearemanywaystobuildthebackendforaniOSapplicationbutyouonly needone.AnddependingonthecomplexityoftheAPIyouaregoingtocreate, differentsolutionsworkbestfordifferentapplications. JustasRailsmakesitpossibletosetupabasicwebapplicationinamatterof minutes, RailsmakesitpossibletosetupabasicAPIinamatterofminutes. ButdecidinghowtostructureyourAPIisn’teasy. Whileexperimentingwithall oftheoptionsisafunweekendproject,sometimesyoujustwanttogetgoing. Thisbookwillhelpyoudojustthat. WhileyourAPIwillnodoubtrequiresome tweakingwhilefleshingoutyouriOSapp,theapproachwewillbetakingisto defineandbuildtheAPIfirst,andthenconsumethisAPIthroughouriOSapp. TheRailsportionsof iOSonRailswillguideyouthroughwhatwehavefound tobearobust, clean, flexiblewayofbuildingoutaJSONAPIwithRails. We providecodesamplesforGET,POST,andPATCHrequests. Inaddition,wewill exploresomeofthealternativeapproachesthatwedidn’tchooseandexplain whywemadethechoicesthatwedid. TheiOSportionofthebookwillthenwalk,step-by-step,throughcreatingan iOSapplicationthatworkswiththeRailsAPIyoujustcreated. TheiOSappli- cationwilluseeachendpointtopostupobjectsandgetbacknecessarydata fortheuser. OurmodelobjectsintheiOSappwillcorrespondwiththemodel objectsinthedatabase,andbepopulatedwithresponsedatafromtheAPI. iv INTRODUCTION v Whoisthisbookfor? ThisbookisforadeveloperwhowantstobuildaniOSapplicationwithaRails backend. It’salsoabookforbothaRailsdeveloperandaniOSdeveloperto shareanduseinconcerttocreateanappquicklyandwithmoreflexibilityto changeitthanabackend-as-a-serviceproviderlikeStackMoborParse. TheapproachsharedinthisbookistheresultofourownexperimentsasRails andiOSdevelopersworkingtogethertobuildanapplication.TheRailsportions ofthisbookassumeabasicworkingknowledgeofhowtobuildawebappli- cationwithRailsaswellastheRubyprogramminglanguage. TheiOSportions ofthisbookassumeexperiencewithobjectorientedprogrammingandabasic familiaritywiththeObjective-Cprogramminglanguage. Thisbookisintendedtobeusedasaguideratherthanarecipe. Whileour aimistogiveyouallofthetoolsnecessarytobuildgreatRailsAPIsandiOS clients,itdoesnotcoverthefundamentalsofRuby,RailsorObjective-C.That beingsaid,ifanypartofthebookstrikesyouasincompleteorconfusing,we arealwayshappytoreceivepullrequestsandissuesubmissionsonGitHub. Part I Building the Humon Rails App 1 Introduction to our example application and setup Exampleapplication WewilluseafakeexampleapplicationcalledHumontoexplainanddemon- stratetheconceptsthroughoutthisbook. Humonisanappthatletsyoufind nearbyevents. IntheHumonapplication,ausercanhavemanyeventsasaneventowner. An eventhasgeolocationinformation(latitudeandlongitude),whichallowsusto plotitonamap. Auserhasandbelongstomanyeventsthroughattendances. Ausercanonlyhaveoneattendanceperevent. TheHumonapplicationdoesnotaskforausernameorpassword. Instead,we willuseanIDuniquetothedevice(‘devicetoken’)totrackuniqueusers. The iOSportionofthebookwilldiscusswherethistokencomesfrom. Fornow,all youneedtoknowisthatusersareidentifiedbytheirdevices. Thisapproach doesnotallowformultipleusersperdeviceorasingleaccountacrossdevices, butitdoesenableuserstostartusingtheapplicationimmediately. Ourdesire tocreatethesimplestapplicationpossibleledustochooseimmediateusability overamorecomplexauthenticationsystem. Wewillprovidecodesnippetsincontext,butyoucanalsoviewtheentireex- ampleapplicationinGitHubtoseehowitisstructured. 2 CHAPTER1. INTRODUCTIONTOOUREXAMPLEAPPLICATIONANDSETUP3 Figure1.1: Humondatabaserepresentation

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.