Share
Embed
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
Transcript
24 slides
-
About me • Backend developer at Parse, by day
• Mobile app maker, by night -
Apps I made • GonePixel.com – Art Gala
– FluffyCreatures • MagicAnywhere.com -
I need a cloud • Key-‐value or Relational store
• File store • User management • Push notification • In-‐app purchases -
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 -
That’s not all! • Mobile plumbing – JSON parsing
– Data access API design – Client logic for retrying, caching, users -
DIY Cloud • A lot of technologies •
A lot of boilerplate code • A lot of unimaginative work -
All I want • Save an object: !
[gameScore setObject:@"Andrew" forKey:@”player"];! [gameScore setObject:@100 forKey:@”score"];! [gameScore save];! -
All I want • Sign up a user:
PFUser *user = [PFUser user];! user.username = @"Andrew";! user.password = @”love";! [user signUp]; -
Welcome to Parse! • Simple • Instant Backend
• Scalable • Reliable -
Registration • Register with Parse to get a key
and app id • In AppDelegate.m, you write: ! #import <Parse/Parse.h> [Parse setApplicationId:@”…” clientKey:@”…"]; -
Storing Objects PFObject *score = [PFObject objectWithClassName:@”Score"]; ! [score
setObject:@"Andrew" forKey:@”player"];! [score setObject:@100 forKey:@”points"];! [score save];! ! ! -
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. -
Retrieving Objects PFQuery *query = [PFQuery queryWithClassName:@"Score"];! NSArray *scores
= [query findObjects];! for (PFObject *score in scores) {! NSLog(@”%@", [score objectForKey:@"points"]);! NSLog(@"%@", [score objectForKey:@”player"]);! } -
Complex PFQuery PFQuery *query = [PFQuery queryWithClassName:@"Score"];! [query whereKey:@"player"
hasPrefix:@"A"];! [query whereKey:@"score" equalTo:@100];! NSArray *scores = [query findObjects]; -
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]; -
Users • Sign up • Log in
• Log out • Anonymous users • Email verification • Forgotten password • Facebook, Twitter login -
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);! }! }]; -
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.! }! }]; -
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 -
PFLogInViewController PFLogInViewController *controller = [[PFLogInViewController alloc] init];! controller.delegate =
self;! [self presentViewController:controller animated:YES completion:nil]; -
Push Notifications • Send a push: [PFPush sendPushMessageToChannelInBackground:@""!
withMessage:@"Usain Bolt wins!"]; • Receive a push: [PFPush subscribeToChannelInBackground:@""]; -
Thanks! • iOS, Android, JS, REST • Parse.com
• @andruwang • [email protected]