introduction to parse backend for mobile developers
DESCRIPTION
Introduction to Parse mobile backend service. Presented at Armenian Developer's Meetup #3 on 10/14/2014.TRANSCRIPT
Writing Parse AppsArmenian Dev Meetup
What is MBaaS?
Why Parse?
● Learning curve● Documentation● Examples● Support
● Platform for mobile developers● Founded Jun 2011, YC● Acquired by Facebook, Apr 2013● Built on Amazon Web Services
Parse
Parse Architecture
Products
Client SDKs
Quickstart
Object Model
PFObject - unstructured key-value data objectPFObject *book = [PFObject objectWithClassName:@”Book”];book[@”title”] = @”The Little Prince”;[book saveInBackground];...int pages = [[book objectForKey:@”pages”] intValue];NSString *objectId = hotel.objectId;NSDate *createdAt = hotel.createdAt; (updatedAt)...[book saveEventually];
QueriesPFQuery *query = [PFQuery queryWithClassName:@”Book”];[query getObjectInBackgroundWithId:@”xWMyZ4YEGZ” block:^(PFObject *book, NSError *error) {
NSLog(@”%@”, book);}…[query whereKey:@”author” equalTo:@”Jack London”];[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError
*error) {…}]…query.limit = 5; query.skip = 10;[query orderByAscending:@”title”];[query selectKeys:@[@”title”, @”pages”];
Relational QueriesPFQuery *query = [PFQuery queryWithClassName:@”Comment”];[query whereKey:@”book” equalTo:theBook];…PFQuery *innerQuery = [PFQuery queryWithClassName:@”Book”];[innerQuery whereKeyExists:@”image”];PFQuery *query = [PFQuery queryWithClassName:@”Comment”];[query whereKey:@”book” matchesQuery:innerQuery];…query.cachePolicy = kPFCachePolicyNetworkElseCache;[query includeKey:@”author”];…PFQuery *query = [PFQuery orQueryWithSubqueries:@[queryA, queryB]];
Files and ImagesNSData *data = UIImagePNGRepresentation(image); // (up to 10MB)PFFile *file = [PFFile filwWithName:@”attachment.png” data:data];[file saveInBackground]; …PFObject *message = [PFObject objectWithClassName:@”Message”];message[@”attatchment”] = file;[message saveInBackground];…PFFile *imageFile = article[@”imageFile”];[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {if (!error) {UIImage *image = [UIImage imageWithData:data];}];
Users
PFUser - user subclass of PFObjectPFUser *user = [PFUser user];user.username = @“myname”; // requireduser.password = @”mypass”; // required on signupuser.email = @”[email protected]”; // optional[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error){...}];[PFUser logInUsernameInBackground@”myname” password:@”mypass” block:^(PFUser *user, NSError *error) {...}];PFUser *currentUser = [PFUser currentUser];[PFUser logOut];[PFUser requestPasswordRequestForEmailInBackground:@”[email protected]”];
Social Integrations
● Facebook and Twitter● Login & Signup● Link & unlinking existing users● API calls
Cloud Code
● Custom code on server● Command line tool (parse new, deploy)Parse.Cloud.define(“hello”, function(request, response) {
response.success(“hello world”); // 15 sec limit});[PFCloud callFunctionInBackground:@”hello” withParameters:@{}
block:^(NSString *results, NSError *error) {...} }];Parse.Cloud.beforeSave(“Book”, …); // 3 sec limitParse.Cloud.afterDelete(Parse.User, …);
UI Components
● PFLoginViewController● PFSignUpViewController ● PFQueryTableViewController● PFImageView● PFTableCellView
Data Browser
Analytics
Pricing
Recommendations
● Prototyping● Wrap Parse API● Development vs. Production● ACL● Cloud Code
Q&A
Thanks!