parse introduction

52
初めての Parse 株式会社 ミクシィ 田村 航弥 12723日月曜日

Upload: tamura-koya

Post on 15-Jan-2015

6.057 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Parse introduction

初めての Parse株式会社 ミクシィ田村 航弥

12年7月23日月曜日

Page 2: Parse introduction

agenda

• @tamotamago

• what’s Parse?

• Data Store

• Query

• Push Notification

12年7月23日月曜日

Page 3: Parse introduction

@tamotamago について

12年7月23日月曜日

Page 4: Parse introduction

@tamotamago について• 田村 航弥

• 東京 2 年目 iOS App developer

• mixi for iPhone, iPad 開発

• http://alpha.mixi.co.jp/2012/10974/• tamotamago.com

12年7月23日月曜日

Page 5: Parse introduction

@tamotamago について

• 第2回 iphone_dev_jp 東京iPhone/Mac勉強会

http://alpha.mixi.co.jp/2012/11000/

mixi の iOS アプリ開発

@k_kinukawa

12年7月23日月曜日

Page 6: Parse introduction

What’s Parse?

12年7月23日月曜日

Page 7: Parse introduction

What’s Parse

• Parse は BaaS (Backend as a Service)

12年7月23日月曜日

Page 8: Parse introduction

What’s Parse

• Parse の機能

•ユーザ認証機能

•データストア、検索

• remote notification

• twitter, facebok SDK をラップ

• and so on ...12年7月23日月曜日

Page 9: Parse introduction

12年7月23日月曜日

Page 10: Parse introduction

Parse の導入

• Parse Quick Start

• tamotamago.com [Objective-C][Parse]初めてのParse ー導入編ー

12年7月23日月曜日

Page 11: Parse introduction

Data Storehttps://parse.com/docs/ios/api/Classes/PFObject.html

12年7月23日月曜日

Page 12: Parse introduction

Data Store

• Key Value Store

•ブラウザからデータ閲覧、編集が可能

•リレーションも持たせることができる

12年7月23日月曜日

Page 13: Parse introduction

Data Store

12年7月23日月曜日

Page 14: Parse introduction

Data Store

テーブル名みたいなもの かってにつくられる

自分でつくっていく

12年7月23日月曜日

Page 15: Parse introduction

Save -blocks-

PFObject *object = [[PFObject alloc]initWithClassName:@"TestClass"];[object setObject:@"tamotamago" forKey:@"name"];[object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { NSString *result = succeeded ? @"success" : @"error"; NSLog(@"result : %@", result);}];

12年7月23日月曜日

Page 16: Parse introduction

Save -callbacks-- (void)viewDidLoad{ [super viewDidLoad];! // Do any additional setup after loading the view, typically from a nib. PFObject *object = [[PFObject alloc]initWithClassName:@"TestClass"]; [object setObject:@"tamotamago2" forKey:@"name"]; [object saveInBackgroundWithTarget:self selector:@selector(saveCallback:error:)];}

-(void)saveCallback:(NSNumber*)result error:(NSError*)error{ if(!error){ NSLog(@"%@", result); }else{ NSLog(@"%@", error); }}

12年7月23日月曜日

Page 17: Parse introduction

UpdatePFObject *object = [[PFObject alloc]initWithClassName:@"TestClass"];[object setObject:@"tamotamago3" forKey:@"name"];[object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { [object setObject:@"tamotamago4" forKey:@"name"]; [object save];}];

PFObject が 1 タプル

12年7月23日月曜日

Page 18: Parse introduction

Array Data

PFObject *object = [[PFObject alloc]initWithClassName:@"TestClass"];NSArray *names = [NSArray arrayWithObjects:@"tamotamago5", @"tamotamago6", nil];[object addUniqueObjectsFromArray:names forKey:@"names"];[object save];

12年7月23日月曜日

Page 19: Parse introduction

Relation -one-to-many-

Post

Comment Comment Comment

parent

12年7月23日月曜日

Page 20: Parse introduction

Relation -one-to-many-PFObject *myPost = [PFObject objectWithClassName:@"Post"];[myPost setObject:@"I'm Hungry" forKey:@"title"];[myPost setObject:@"Where should we go for lunch?" forKey:@"content"]; // Create the commentPFObject *myComment = [PFObject objectWithClassName:@"Comment"];[myComment setObject:@"Let's do Sushirrito." forKey:@"content"]; // Add a relation between the Post and Comment[myComment setObject:myPost forKey:@"parent"]; // This will save both myPost and myComment[myComment saveInBackground];

12年7月23日月曜日

Page 21: Parse introduction

Relation -one-to-many-PFObject *myPost = [PFObject objectWithClassName:@"Post"];[myPost setObject:@"I'm Hungry" forKey:@"title"];[myPost setObject:@"Where should we go for lunch?" forKey:@"content"]; // Create the commentPFObject *myComment = [PFObject objectWithClassName:@"Comment"];[myComment setObject:@"Let's do Sushirrito." forKey:@"content"]; // Add a relation between the Post and Comment[myComment setObject:myPost forKey:@"parent"]; // This will save both myPost and myComment[myComment saveInBackground];

12年7月23日月曜日

Page 22: Parse introduction

Relation -many-to-many-

PostPost Post

user useruser

like

12年7月23日月曜日

Page 23: Parse introduction

Relation -many-to-many-Parse blog : A More Scalable Many-to-Many Approach

PFObject *post2 = [PFObject objectWithClassName:@"Post"];[post2 setObject:@"I'm Hungry" forKey:@"title"];[post2 setObject:@"Where should we go for dinner?" forKey:@"content"];PFRelation *relation = [post2 relationforKey:@"likes"];

for (PFObject *object in objects){ [relation addObject: object];}

[post2 save];

12年7月23日月曜日

Page 24: Parse introduction

Relation -many-to-many-Parse blog : A More Scalable Many-to-Many Approach

PFObject *post2 = [PFObject objectWithClassName:@"Post"];[post2 setObject:@"I'm Hungry" forKey:@"title"];[post2 setObject:@"Where should we go for dinner?" forKey:@"content"];PFRelation *relation = [post2 relationforKey:@"likes"];

for (PFObject *object in objects){ [relation addObject: object];}

[post2 save];

12年7月23日月曜日

Page 25: Parse introduction

Relation -many-to-many-Parse blog : A More Scalable Many-to-Many Approach

PFObject *post2 = [PFObject objectWithClassName:@"Post"];[post2 setObject:@"I'm Hungry" forKey:@"title"];[post2 setObject:@"Where should we go for dinner?" forKey:@"content"];PFRelation *relation = [post2 relationforKey:@"likes"];

for (PFObject *object in objects){ [relation addObject: object];}

[post2 save];

12年7月23日月曜日

Page 26: Parse introduction

Querieshttps://parse.com/docs/ios/api/Classes/PFQuery.html

12年7月23日月曜日

Page 27: Parse introduction

Basic Query

12年7月23日月曜日

Page 28: Parse introduction

Basic QueryPFQuery *query = [PFQuery queryWithClassName:@"TestClass"];[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (!error) { // The find succeeded. for (PFObject *object in objects){ NSLog(@"object name -> %@", [object objectForKey:@"name"]); } } else { // Log details of the failure NSLog(@"Error: %@ %@", error, [error userInfo]); }}];

2012-07-20 13:14:29.786 ParseTest[948:f803] object name -> tamotamago2012-07-20 13:14:29.787 ParseTest[948:f803] object name -> tamotamago22012-07-20 13:14:29.787 ParseTest[948:f803] object name -> tamotamago42012-07-20 13:14:29.788 ParseTest[948:f803] object name -> (null)2012-07-20 13:14:29.788 ParseTest[948:f803] object name -> tamotamago7

12年7月23日月曜日

Page 29: Parse introduction

Basic QueryPFQuery *query = [PFQuery queryWithClassName:@"TestClass"];[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (!error) { // The find succeeded. for (PFObject *object in objects){ NSLog(@"object name -> %@", [object objectForKey:@"name"]); } } else { // Log details of the failure NSLog(@"Error: %@ %@", error, [error userInfo]); }}];

2012-07-20 13:14:29.786 ParseTest[948:f803] object name -> tamotamago2012-07-20 13:14:29.787 ParseTest[948:f803] object name -> tamotamago22012-07-20 13:14:29.787 ParseTest[948:f803] object name -> tamotamago42012-07-20 13:14:29.788 ParseTest[948:f803] object name -> (null)2012-07-20 13:14:29.788 ParseTest[948:f803] object name -> tamotamago7

12年7月23日月曜日

Page 30: Parse introduction

Where 句

[query whereKey:@"name" equalTo:@"tamotamago"];

12年7月23日月曜日

Page 31: Parse introduction

OrderBy

[query orderByAscending:@"name"];

12年7月23日月曜日

Page 32: Parse introduction

IN 句

NSArray *array = [NSArray arrayWithObjects: @"tamotamago", @"tamotamago2", nil];[query whereKey:@"name" containedIn:array];

12年7月23日月曜日

Page 33: Parse introduction

Relation query

12年7月23日月曜日

Page 34: Parse introduction

Relation query

PFQuery *query = [[PFQuery alloc] initWithClassName:@"Post"];[query findObjectsInBackgroundWithBlock:^(NSArray *posts, NSError *error) { for (PFObject *post in posts){ PFRelation *relation = [post relationforKey:@"likes"]; PFQuery *relationQuery = [relation query]; [relationQuery findObjectsInBackgroundWithBlock:^(NSArray *tamotamagos, NSError *error) { for(PFObject *object in tamotamagos){ NSLog(@"%@", [object objectForKey:@"name"]); } }]; }}];

12年7月23日月曜日

Page 35: Parse introduction

Paging

[query findObjects]; query.skip = 3;[query findObjects];

object name -> tamotamagoobject name -> tamotamago2object name -> tamotamago4object name -> (null)object name -> tamotamago7

object name -> (null)object name -> tamotamago7

12年7月23日月曜日

Page 36: Parse introduction

Push Notificationhttps://parse.com/docs/ios/api/Classes/PFPush.html

12年7月23日月曜日

Page 37: Parse introduction

Setup

https://www.parse.com/tutorials/ios-push-notifications

証明書の発行とか

12年7月23日月曜日

Page 38: Parse introduction

Setup

12年7月23日月曜日

Page 39: Parse introduction

Setup- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ // Override point for customization after application launch. [Parse setApplicationId:@"app id" clientKey:@"client key"]; [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge| UIRemoteNotificationTypeAlert| UIRemoteNotificationTypeSound]; return YES;}

- (void)application:(UIApplication *)applicationdidRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken{ // Tell Parse about the device token. [PFPush storeDeviceToken:newDeviceToken]; // Subscribe to the global broadcast channel. [PFPush subscribeToChannelInBackground:@""];}

12年7月23日月曜日

Page 40: Parse introduction

12年7月23日月曜日

Page 41: Parse introduction

channel

Push を投げるゾーン

12年7月23日月曜日

Page 42: Parse introduction

channel

- (void)application:(UIApplication *)applicationdidRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken{ // Tell Parse about the device token. [PFPush storeDeviceToken:newDeviceToken]; // Subscribe to the global broadcast channel. [PFPush subscribeToChannelInBackground:@""]; [PFPush subscribeToChannelInBackground:@"tamotamago"];}

12年7月23日月曜日

Page 43: Parse introduction

channel

Broadcast

tamotamago

12年7月23日月曜日

Page 44: Parse introduction

channel

12年7月23日月曜日

Page 45: Parse introduction

channel

Broadcasttamotamagotamotamago2

tamotamago3

12年7月23日月曜日

Page 46: Parse introduction

send notification

PFPush *push = [[PFPush alloc] init];NSArray *channels = [NSArray arrayWithObjects:@"tamotamago", nil];[push setChannels:channels];[push setMessage:@"push test"];[push sendPushInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { }];

12年7月23日月曜日

Page 47: Parse introduction

channel

Broadcasttamotamagotamotamago2

tamotamago3

push!!

12年7月23日月曜日

Page 48: Parse introduction

おわりに

12年7月23日月曜日

Page 49: Parse introduction

Others

• Users• https://parse.com/docs/ios/api/Classes/PFUser.html

• Geo Points• https://parse.com/docs/ios/api/Classes/PFGeoPoint.html

• Facebook Users• https://parse.com/docs/ios/api/Classes/PFFacebookUtils.html

• and so on ...

12年7月23日月曜日

Page 50: Parse introduction

でもお高いんでしょう?

12年7月23日月曜日

Page 51: Parse introduction

12年7月23日月曜日

Page 52: Parse introduction

enjoy

12年7月23日月曜日