More Related Content
Similar to Getting started with CloudKit
Similar to Getting started with CloudKit (20)
More from Yuichi Yoshida (11)
Getting started with CloudKit
- 1. Framework
Getting started with CloudKit
What can you do using CloudKit?
Yuichi Yoshida
Chief engineer, DENSO IT Laboratory, Inc.
#yidev
@sonson_twit
© 2014 Yuichi Yoshida, all rights reserved. Redistribution or public display not permitted without written permission from Yuichi Yoshida.
- 2. 自己紹介
2tchの中の人
• iOS好きです
• 2tch(2ちゃんねるビューア)
• iOS SDK Hacksなど
• 研究
• コンピュータビジョン
• 機械学習
• 研究・開発
• 画像検索サービス
• 車向けのサービスやハードウェア
- 3. 発表概要
It works?
• Overview
• Public and Private
• Subscription
• CKOperation
• Save policy
• CloudKit Dashboard
- 4. Overview
What is CloudKit?
• iCloudのAPI
• AppleのiCloudの写真共有もこれで実装してるらしい
• iCloudのファイル共有
• iCloudのCoreDataも?
• Apple謹製Parse?
• というほど使い勝手はよくない
• iOS/OSX専用のちょっとしたクラウドAPI
- 5. 何ができる?
CKRecord
• CKRecordクラスを使ってデータを登録
• データはkey-value方式でセット
• データはそのまま使わないでね by Apple
• NSPredicateを使って検索
• 2種類のデータ
• データは誰からもアクセスできるPublic
• 本人しかアクセスできないPrivate
- 6. Add&Edit
CKDatabase *database
= [[CKContainer defaultContainer] publicCloudDatabase];
CKRecord *newRecord
= [[CKRecord alloc] initWithRecordType:@“comment"];
[newRecord setObject:_textField.text forKey:@"text"];
[newRecord setObject:@(refTime) forKey:@“time"];
[database saveRecord:newRecord
completionHandler:^(CKRecord *saved, NSError *error) {
// error handling
}];
- 7. Fetch
NSPredicate *predicate
= [NSPredicate predicateWithFormat:@"time > 0"];
CKQuery *query
= [[CKQuery alloc] initWithRecordType:@"comment"
predicate:predicate];
[database performQuery:query
inZoneWithID:nil
completionHandler:^(NSArray *results, NSError *error) {
// handling results or error
}];
- 8. Public or Private
• Public
• 誰でも読める(書き込みは設定が必要)
• 通知が使える(subscribe)
• Private
• アカウント本人しか読めない
• token, policyによるconflict管理
- 10. Subscribe
NSPredicate *truePredicate
= [NSPredicate predicateWithValue:YES];
CKSubscription *itemSubscription
= [[CKSubscription alloc] initWithRecordType:@"comment"
predicate:truePredicate
options:CKSubscriptionOptionsFiresOnRecordCreation];
CKNotificationInfo *notification
= [[CKNotificationInfo alloc] init];
notification.alertBody
= @"New comment has been added.”;
itemSubscription.notificationInfo
= notification;
[database saveSubscription:itemSubscription
completionHandler:^(CKSubscription *subscription, NSError
*error) {
// handling subscription ID or, error.
}];
- 11. NSOperationQueue
Use the force, Luke.
• 一連の操作はCKOperationで実行できる
• 追加,編集,削除,検索
• ・・・などのCKOperationのサブクラスがある
• 依存関係
• 検索結果に対して・・処理みたいなことを書ける
- 12. CKOperation
CKModifyRecordsOperation *operation
= [[CKModifyRecordsOperation alloc] initWithRecordsToSave:records
recordIDsToDelete:recordIDs];
// for confliction
operation.savePolicy
= CKRecordSaveIfServerRecordUnchanged;
operation.modifyRecordsCompletionBlock
= ^(NSArray *savedRecords, NSArray *deletedRecordIDs, NSError
*error) {
};
operation.perRecordCompletionBlock
= ^(CKRecord *record, NSError *error) {
};
operation.perRecordProgressBlock
= ^(CKRecord *record, double progress) {
};
- 13. 課題
Write bug reports, Luke.
• CKRecordは,ローカルにキャッシュされない
• キャッシュは自前で作る必要がある
• ドキュメントにはされるって書いて合ったような
• バグが多い,つーか多すぎる
• subscriptionが動かない
• 通知が来ない
• savePolicyが効いてない
- 15. CloudKit Dashboard
Can Apple create web services?
• CloudKit Dashboard
• ブラウザでデータを閲覧・編集
• Xcode,Certification centerから飛べる
• Subscriptionの確認など
• Privateのデータは見えない
- 17. まとめ
• Concept
• Apple謹製のBaaSのような・・・・
• CKRecord
• Add, Edit, Fetch
• Subscription
• CKOperation