SlideShare una empresa de Scribd logo
1 de 36
Lessons from developing anIphone App + Server backend Sujee Maniyam s@sujee.net http://sujee.net http://DiscountsForMe.net Aug 2009
Target Audience Iphone app developers Server backend developers for mobile apps Expert level: Beginner - Intermediate
My Background Developer (enterprise, web) Java / Php / Ruby First iphone/mobile app
App: DiscountsForMe Shows member benefits Based on location V1.0 in app store Memberships: Public radio (KQED) Bank of America card AAA, AARP More…
Architecture Server (DiscountsForMe.net) serves data Server is Rails app Iphone app talks to the server <Insert usual SERVER ---- INTERNET CLOUD ---- IPHONEpicture here>
Agenda Connectivity Data format Secure Data trasnfer UDIDs  & Keys Controlling app from server
Connectivity : Simple Start App makes three server calls ping() get_memberships() get_discounts(my_location, my_memberships) Simulator   Iphone over Wi-fi Iphone over 3G  LAG-TIME is a problem
Connectivity : Minimize Lag Time Noticeable lag time over 3G/Edge Reducing lag time Condense network calls (especially if the user is waiting for data) Download in background So Get_memberships() Get_discounts(my_location, my_memberships) get_memberships_and_discounts(loc, mymems)
Iphone Connectivity BIG LESSON 1 :  Test on IPHONE (not just simulator) Test with WiFi OFF!  (3G can be slow to connect, EDGE even worse) You may need to reorganize the logic to improve response time (I had to) LESSON 2 Test in AirPlane Mode (all RADIOS off)(a frequent reason network apps are rejected )
Connectivity Test Quick Ping Which is faster? httpS://www.DiscountsForMe.net/ping http://www.google.com SSL always takes longer to establish connection Use faster sites Another snippet from Erica Sadun’s book(to be verified)
Talking to Server : Format Two choices :   XML, JSON JSON smaller size than XML (50% less) Json  : use TouchJSON library http://code.google.com/p/touchcode/wiki/TouchJSON XML : NSXML(sdk)  / TouchXML / KissXMLhttp://www.71squared.co.uk/2009/05/processing-xml-on-the-iphone/
Agenda Connectivity Data format Secure Data transfer UDIDs, Keys, analytics Controlling app from server
Secure Data Transfer Plain HTTP is fine most of the time If you want to secure data Symmetric key encryption (shared ‘seckr3t’ key on Iphone app and server) Public-private key encryption (e.g. SSH) : private key on server, public key on iphone httpS
Secure data transfer : httpS SSL is ‘good enough’ for most of us Get a proper SSL certificate ($30).  Self-signed certs don’t work by default Beware connection time is a little longer for httpS Verify your ssl certificate is installed properlyhttp://www.digicert.com/help/
Verify SSL Cert…
Talking to Server : POST req NSMutableURLRequest *request  = [NSMutableURLRequestrequestWithURL:url]; [request setHTTPMethod:@"POST"]; NSMutableString *postString = [NSMutableString string]; [postStringappendFormat:@"%@=%@&", key, value]; NSString *postString2 = [postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [request setHTTPBody:[postString2 dataUsingEncoding:NSUTF8StringEncoding]]; NSURLResponse *response = nil; NSError *error = nil; NSData *data = [NSURLConnectionsendSynchronousRequest:requestreturningResponse:&responseerror:&error];
Talking to Server : Local Server #ifdef DEBUG// dev #define MEMBER_SERVER @”http://localhost:3000” #else// production #define MEMBER_SERVER @”https://discountsforme.net” #endif - And define ‘DEBUG’ in build configurations
Talking to Server : Dedicated Class ,[object Object]
Easy to debug
Use named methods (getDiscounts Vs connectToURL)@interface ServerConnection : NSObject { } + (BOOL) testConnectivity; + (BOOL) isConnected; + (NSArray *) getMemberships; + (NSArray *) getDiscounts:(NSDictionary *) params; @end
Agenda Connectivity Data format Secure Data transfer UDIDs, Keys, multiple versions, analytics Controlling app from server
What do I send to the server? get_memberships() No parameters?... Think about including UDID (device id) And a Key (compiled within the app) http://discountsforme.net/iphone/get_memberships http://discountsforme.net/iphone/get_memberships?udid=xxxx&key=yyyy
Server Side : Unique Device ID Each mobile device has a uniq ID, etched in hardware (just like MAC address) Your app can send UDID with each request Of course : encrypt it  or via SSL Very useful for metrics on app usage How many unique devices have the app Access patterns (repeat uses) Easy account creation (no signup)
Server side : access keys Start using ‘access keys’ from day-1 Sample key = “iphone_v1.0_xklajdfoi2” (human readable + hard to guess) Each request to server must have a valid key Easy to control client access Prevent scraping, DOS ..etc Monitoring (what versions are being used) Support multiple versions, easy upgrade
Supporting multiple versions May be supporting 2-3 client versions at a time (users don’t always run the latest) Keep old ‘API’ around, build-out new API		if (is_v2_or_later(key))		{   do something }		else 		{do some thing else} This can get convoluted (see next page…)
Supporting multiple clients…
Supporting Multiple Clients… Have different controllers handle different client versions#define SERVER @”https://foo.com/iphone1”#define SERVER @”https://foo.com/iphone2” Make sure to avoid code duplication Plan-B : End-of-life  If ( !  is_supported_version(key)){send_msg(“please upgrade”);}
Server side : keeping it secure Make sure ‘secret stuff’ doesn’t get logged in log-files In Rails : class Mobile::MobileController < ApplicationControllerfilter_parameter_logging [:key, :uid] 	end Output: Processing IphoneController#get_memberships_and_discounts (for 166.137.132.167 at 2009-07-02 16:07:41) [POST]   Session ID: 126e5a73742f92f85c1158ea63fd960a   Parameters: {"loc"=>"39.282440,-76.765693", "action"=>"get_memberships_and_discounts", "uid"=>”[FILTERED]", "controller"=>"mobile/iphone", "dist"=>"25", "mems"=>"", "key"=>"[FILTERED]"}
Server side : Metrics : Logs Log every thing to database, don’t rely on logfiles This gives you pretty good metrics on your app usage On Rails, use around_filteraround_filter  :log_access,  :only => [:get_discounts, :get_memberships] Thirdparty metrics :   FLURRY, PinchMedia…
Server side : logging in Rails def log_access start_time = Time.now yield end_time = Time.now     elapsed = ((end_time - start_time)*1000.0).to_int     begin # b/c we don’t want to error during logging alog = MemberAccessLog.new alog.client_type_id = client_type_id alog.session = session.session_id       …. alog.save! rescue    end End
Logging & Scalability If all your requests are READ-ONLY (from db) it is very easy to scale Load balancer can route requests to any server Database can be replicated easily Write-bound apps are little tricky to scale
Agenda Connectivity Data format Secure Data transfer UDIDs, Keys, analytics Controlling app from server
Controlling app behavior from Server
Control … Apps changes are not easy to ‘get out’ Approval process takes time Users may not upgrade to latest version Server changes are under your control and easy to deploy So build in control-switches in the app, that can be directed from server
Control… One example:  Choosing if you are going to show ads? show_ads : {none | admob | tapjoy}

Más contenido relacionado

Destacado (8)

Interpolation and extrapolation
Interpolation and extrapolationInterpolation and extrapolation
Interpolation and extrapolation
 
Interpolation
InterpolationInterpolation
Interpolation
 
interpolation
interpolationinterpolation
interpolation
 
Introduction to wavelet transform
Introduction to wavelet transformIntroduction to wavelet transform
Introduction to wavelet transform
 
Image pre processing
Image pre processingImage pre processing
Image pre processing
 
Interpolation Methods
Interpolation MethodsInterpolation Methods
Interpolation Methods
 
architecture of mobile software applications
architecture of mobile software applicationsarchitecture of mobile software applications
architecture of mobile software applications
 
discrete wavelet transform
discrete wavelet transformdiscrete wavelet transform
discrete wavelet transform
 

Más de Sujee Maniyam

Más de Sujee Maniyam (9)

Reference architecture for Internet of Things
Reference architecture for Internet of ThingsReference architecture for Internet of Things
Reference architecture for Internet of Things
 
Hadoop to spark-v2
Hadoop to spark-v2Hadoop to spark-v2
Hadoop to spark-v2
 
Building secure NoSQL applications nosqlnow_conf_2014
Building secure NoSQL applications nosqlnow_conf_2014Building secure NoSQL applications nosqlnow_conf_2014
Building secure NoSQL applications nosqlnow_conf_2014
 
Hadoop2 new and noteworthy SNIA conf
Hadoop2 new and noteworthy SNIA confHadoop2 new and noteworthy SNIA conf
Hadoop2 new and noteworthy SNIA conf
 
Launching your career in Big Data
Launching your career in Big DataLaunching your career in Big Data
Launching your career in Big Data
 
Hadoop security landscape
Hadoop security landscapeHadoop security landscape
Hadoop security landscape
 
Spark Intro @ analytics big data summit
Spark  Intro @ analytics big data summitSpark  Intro @ analytics big data summit
Spark Intro @ analytics big data summit
 
Cost effective BigData Processing on Amazon EC2
Cost effective BigData Processing on Amazon EC2Cost effective BigData Processing on Amazon EC2
Cost effective BigData Processing on Amazon EC2
 
Iphone client-server app with Rails backend (v3)
Iphone client-server app with Rails backend (v3)Iphone client-server app with Rails backend (v3)
Iphone client-server app with Rails backend (v3)
 

Último

Último (20)

Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Lessons from developing a Client Server Iphone app

  • 1. Lessons from developing anIphone App + Server backend Sujee Maniyam s@sujee.net http://sujee.net http://DiscountsForMe.net Aug 2009
  • 2. Target Audience Iphone app developers Server backend developers for mobile apps Expert level: Beginner - Intermediate
  • 3. My Background Developer (enterprise, web) Java / Php / Ruby First iphone/mobile app
  • 4. App: DiscountsForMe Shows member benefits Based on location V1.0 in app store Memberships: Public radio (KQED) Bank of America card AAA, AARP More…
  • 5.
  • 6. Architecture Server (DiscountsForMe.net) serves data Server is Rails app Iphone app talks to the server <Insert usual SERVER ---- INTERNET CLOUD ---- IPHONEpicture here>
  • 7. Agenda Connectivity Data format Secure Data trasnfer UDIDs & Keys Controlling app from server
  • 8. Connectivity : Simple Start App makes three server calls ping() get_memberships() get_discounts(my_location, my_memberships) Simulator Iphone over Wi-fi Iphone over 3G LAG-TIME is a problem
  • 9. Connectivity : Minimize Lag Time Noticeable lag time over 3G/Edge Reducing lag time Condense network calls (especially if the user is waiting for data) Download in background So Get_memberships() Get_discounts(my_location, my_memberships) get_memberships_and_discounts(loc, mymems)
  • 10. Iphone Connectivity BIG LESSON 1 : Test on IPHONE (not just simulator) Test with WiFi OFF! (3G can be slow to connect, EDGE even worse) You may need to reorganize the logic to improve response time (I had to) LESSON 2 Test in AirPlane Mode (all RADIOS off)(a frequent reason network apps are rejected )
  • 11. Connectivity Test Quick Ping Which is faster? httpS://www.DiscountsForMe.net/ping http://www.google.com SSL always takes longer to establish connection Use faster sites Another snippet from Erica Sadun’s book(to be verified)
  • 12. Talking to Server : Format Two choices : XML, JSON JSON smaller size than XML (50% less) Json : use TouchJSON library http://code.google.com/p/touchcode/wiki/TouchJSON XML : NSXML(sdk) / TouchXML / KissXMLhttp://www.71squared.co.uk/2009/05/processing-xml-on-the-iphone/
  • 13. Agenda Connectivity Data format Secure Data transfer UDIDs, Keys, analytics Controlling app from server
  • 14. Secure Data Transfer Plain HTTP is fine most of the time If you want to secure data Symmetric key encryption (shared ‘seckr3t’ key on Iphone app and server) Public-private key encryption (e.g. SSH) : private key on server, public key on iphone httpS
  • 15. Secure data transfer : httpS SSL is ‘good enough’ for most of us Get a proper SSL certificate ($30). Self-signed certs don’t work by default Beware connection time is a little longer for httpS Verify your ssl certificate is installed properlyhttp://www.digicert.com/help/
  • 17. Talking to Server : POST req NSMutableURLRequest *request = [NSMutableURLRequestrequestWithURL:url]; [request setHTTPMethod:@"POST"]; NSMutableString *postString = [NSMutableString string]; [postStringappendFormat:@"%@=%@&", key, value]; NSString *postString2 = [postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [request setHTTPBody:[postString2 dataUsingEncoding:NSUTF8StringEncoding]]; NSURLResponse *response = nil; NSError *error = nil; NSData *data = [NSURLConnectionsendSynchronousRequest:requestreturningResponse:&responseerror:&error];
  • 18. Talking to Server : Local Server #ifdef DEBUG// dev #define MEMBER_SERVER @”http://localhost:3000” #else// production #define MEMBER_SERVER @”https://discountsforme.net” #endif - And define ‘DEBUG’ in build configurations
  • 19.
  • 21. Use named methods (getDiscounts Vs connectToURL)@interface ServerConnection : NSObject { } + (BOOL) testConnectivity; + (BOOL) isConnected; + (NSArray *) getMemberships; + (NSArray *) getDiscounts:(NSDictionary *) params; @end
  • 22. Agenda Connectivity Data format Secure Data transfer UDIDs, Keys, multiple versions, analytics Controlling app from server
  • 23. What do I send to the server? get_memberships() No parameters?... Think about including UDID (device id) And a Key (compiled within the app) http://discountsforme.net/iphone/get_memberships http://discountsforme.net/iphone/get_memberships?udid=xxxx&key=yyyy
  • 24. Server Side : Unique Device ID Each mobile device has a uniq ID, etched in hardware (just like MAC address) Your app can send UDID with each request Of course : encrypt it or via SSL Very useful for metrics on app usage How many unique devices have the app Access patterns (repeat uses) Easy account creation (no signup)
  • 25. Server side : access keys Start using ‘access keys’ from day-1 Sample key = “iphone_v1.0_xklajdfoi2” (human readable + hard to guess) Each request to server must have a valid key Easy to control client access Prevent scraping, DOS ..etc Monitoring (what versions are being used) Support multiple versions, easy upgrade
  • 26. Supporting multiple versions May be supporting 2-3 client versions at a time (users don’t always run the latest) Keep old ‘API’ around, build-out new API if (is_v2_or_later(key)) { do something } else {do some thing else} This can get convoluted (see next page…)
  • 28. Supporting Multiple Clients… Have different controllers handle different client versions#define SERVER @”https://foo.com/iphone1”#define SERVER @”https://foo.com/iphone2” Make sure to avoid code duplication Plan-B : End-of-life If ( ! is_supported_version(key)){send_msg(“please upgrade”);}
  • 29. Server side : keeping it secure Make sure ‘secret stuff’ doesn’t get logged in log-files In Rails : class Mobile::MobileController < ApplicationControllerfilter_parameter_logging [:key, :uid] end Output: Processing IphoneController#get_memberships_and_discounts (for 166.137.132.167 at 2009-07-02 16:07:41) [POST] Session ID: 126e5a73742f92f85c1158ea63fd960a Parameters: {"loc"=>"39.282440,-76.765693", "action"=>"get_memberships_and_discounts", "uid"=>”[FILTERED]", "controller"=>"mobile/iphone", "dist"=>"25", "mems"=>"", "key"=>"[FILTERED]"}
  • 30. Server side : Metrics : Logs Log every thing to database, don’t rely on logfiles This gives you pretty good metrics on your app usage On Rails, use around_filteraround_filter :log_access, :only => [:get_discounts, :get_memberships] Thirdparty metrics : FLURRY, PinchMedia…
  • 31. Server side : logging in Rails def log_access start_time = Time.now yield end_time = Time.now elapsed = ((end_time - start_time)*1000.0).to_int begin # b/c we don’t want to error during logging alog = MemberAccessLog.new alog.client_type_id = client_type_id alog.session = session.session_id …. alog.save! rescue end End
  • 32. Logging & Scalability If all your requests are READ-ONLY (from db) it is very easy to scale Load balancer can route requests to any server Database can be replicated easily Write-bound apps are little tricky to scale
  • 33. Agenda Connectivity Data format Secure Data transfer UDIDs, Keys, analytics Controlling app from server
  • 35. Control … Apps changes are not easy to ‘get out’ Approval process takes time Users may not upgrade to latest version Server changes are under your control and easy to deploy So build in control-switches in the app, that can be directed from server
  • 36. Control… One example: Choosing if you are going to show ads? show_ads : {none | admob | tapjoy}
  • 37. Hosting Shared hosting is fine, but others might swamp your DB, CPU ..etc If you can, get a VPS (Virtual Private Server) Plans start from $20 / month (SliceHost, Hosting-Rails ..etc) You have full ROOT access to the server (install packages, run CRON jobs ..etc) EC2 is great (for testing, scaling)
  • 38. Thanks! Sujee Maniyam s@sujee.net http://sujee.net http://DiscountsForMe.net Questions?