Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Parse

jamesjyu
August 11, 2012

 Parse

An introduction to the core concepts of Parse and how you can use it to build your mobile application.

Find out more at www.parse.com

Presentation by Andrew Wang

jamesjyu

August 11, 2012
Tweet

More Decks by jamesjyu

Other Decks in Technology

Transcript

  1. About  me   •  Backend  developer  at  Parse,  by  day

      •  Mobile  app  maker,  by  night  
  2. Apps  I  made   •  GonePixel.com   – Art  Gala  

      – FluffyCreatures   •  MagicAnywhere.com      
  3. I  need  a  cloud   •  Key-­‐value  or  Relational  store

      •  File  store   •  User  management   •  Push  notification   •  In-­‐app  purchases  
  4. Building  the  cloud   •  Set  up  a  server  

      –  AWS,  Heroku   •  Set  up  database   –  MySQL,  Postgres,  Mongo   •  Set  up  REST  endpoints   –  Ruby,  PHP,  Python,  Rails,  Django,  Node.js   •  Write  boilerplate  logic   –  User  accounts,  authorization,  authentication  
  5. That’s  not  all!   •  Mobile  plumbing   – JSON  parsing

      – Data  access  API  design   – Client  logic  for  retrying,  caching,  users    
  6. DIY  Cloud   •  A  lot  of  technologies   • 

    A  lot  of  boilerplate  code   •  A  lot  of  unimaginative  work  
  7. All  I  want   •  Save  an  object:   !

    [gameScore setObject:@"Andrew" forKey:@”player"];! [gameScore setObject:@100 forKey:@”score"];! [gameScore save];!
  8. All  I  want   •  Sign  up  a  user:  

      PFUser *user = [PFUser user];! user.username = @"Andrew";! user.password = @”love";! [user signUp];  
  9. Registration   •  Register  with  Parse  to  get  a  key

     and  app  id   •  In  AppDelegate.m,  you  write:   ! #import <Parse/Parse.h>   [Parse setApplicationId:@”…” clientKey:@”…"];  
  10. Storing  Objects   PFObject *score = [PFObject objectWithClassName:@”Score"]; ! [score

    setObject:@"Andrew" forKey:@”player"];! [score setObject:@100 forKey:@”points"];! [score save];! ! !    
  11. PFObject   •  A  PFObject  is  like  a  dictionary  

    – No  schema  required   – You  provide  a  class  name  for  grouping   – String,  number,  boolean,  array,  dictionary,  binary   data,  geopoint,  date.      
  12. Retrieving  Objects   PFQuery *query = [PFQuery queryWithClassName:@"Score"];! NSArray *scores

    = [query findObjects];! for (PFObject *score in scores) {! NSLog(@”%@", [score objectForKey:@"points"]);! NSLog(@"%@", [score objectForKey:@”player"]);! }  
  13. Complex  PFQuery   PFQuery *query = [PFQuery queryWithClassName:@"Score"];! [query whereKey:@"player"

    hasPrefix:@"A"];! [query whereKey:@"score" equalTo:@100];! NSArray *scores = [query findObjects];  
  14. Saving  Files   •  Image  -­‐>  NSData  -­‐>  PFFile  -­‐>

     PFObject   ! UIImage *image = [UIImage imageNamed:@"andrew.jpg"];! NSData *imageData = UIImagePNGRepresentation(image);! PFFile *imageFile = [PFFile fileWithData:imageData];! [imageFile save];! ! PFObject *guest = [PFObject objectWithClassName:@"Guest"];! [guest setObject:@"Andrew" forKey:@"name"];! [guest setObject:imageFile forKey:@"imageFile"];! [guest save];    
  15. Users   •  Sign  up   •  Log  in  

    •  Log  out   •  Anonymous  users   •  Email  verification   •  Forgotten  password   •  Facebook,  Twitter  login  
  16. User  Sign-­‐Up   PFUser *user = [PFUser user];! user.username =

    @"Andrew";! user.password = @"peace";! user.email = @"[email protected]";! ! // other fields can be set like with PFObject! [user setObject:@"425-922-1234" forKey:@"phone"];! [user signUpInBackgroundWithBlock:^(BOOL success, NSError *error) {! if (!error) {! // Success! Let the user uses the app now.! } else {! // probably username is taken! NSLog(@"%@", error);! }! }];  
  17. User  Log-­‐In   [PFUser logInWithUsernameInBackground:@"Andrew" password:@"peace"! block:^(PFUser *user, NSError *error)

    {! if (!error) {! // Success!! NSLog(@"%@", user);! } else {! // Failed.! // Probably incorrect username/password combination.! }! }];  
  18. Forgotten  Passwords   [PFUser requestPasswordResetForEmail:@”[email protected]"];! •  User  requests  that  his

     password  be  reset   •  Parse  sends  an  email  containing  a  special  reset  link   •  User  clicks  on  the  reset  link,  and  is  directed  to  a  special  Parse  page   •  User  types  in  a  new  password  
  19. PFLogInViewController   PFLogInViewController *controller = [[PFLogInViewController alloc] init];! controller.delegate =

    self;! [self presentViewController:controller animated:YES completion:nil];  
  20. Push  Notifications   •  Send  a  push:   [PFPush sendPushMessageToChannelInBackground:@""!

    withMessage:@"Usain Bolt wins!"];   •  Receive  a  push:   [PFPush subscribeToChannelInBackground:@""];