304
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. #WWDC14 Introducing CloudKit A how-to guide for iCloud for your Apps Session 208 Olivier Bonnet CloudKit Client Software Frameworks

208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC14

Introducing CloudKitA how-to guide for iCloud for your Apps

Session 208 Olivier Bonnet CloudKit Client Software

Frameworks

Page 2: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Introduction

iCloud Drive iCloud Photo Library

iCloud CoreData

? Mystery

Page 3: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Introduction

CloudKit

iCloud Drive

iCloud CoreData

iCloud Photo Library

Page 4: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Overview

Page 5: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Overview

What is CloudKit

Page 6: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Overview

What is CloudKit

Enabling CloudKit in your application

Page 7: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Overview

What is CloudKit

Enabling CloudKit in your application

Introduction to the API

Page 8: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Overview

What is CloudKit

Enabling CloudKit in your application

Introduction to the API

User Accounts

Page 9: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Overview

What is CloudKit

Enabling CloudKit in your application

Introduction to the API

User Accounts

When to use CloudKit

Page 10: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

What is CloudKit?

Page 11: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

What is CloudKit?

Access to iCloud servers

Page 12: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

What is CloudKit?

Access to iCloud servers

Supported on OS X and iOS

Page 13: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

What is CloudKit?

Access to iCloud servers

Supported on OS X and iOS

Uses iCloud accounts

Page 14: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

What is CloudKit?

Access to iCloud servers

Supported on OS X and iOS

Uses iCloud accounts

Public and private databases

Page 15: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

What is CloudKit?

Access to iCloud servers

Supported on OS X and iOS

Uses iCloud accounts

Public and private databases

Structured and bulk data

Page 16: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

What is CloudKit?

Access to iCloud servers

Supported on OS X and iOS

Uses iCloud accounts

Public and private databases

Structured and bulk data

Transport, not local persistence

Page 17: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Enabling CloudKit in Your Application

Page 18: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Enabling CloudKit in Your Application

Navigate to your application’s Capabilities pane

Page 19: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Enable iCloud

Enabling CloudKit in Your Application

Page 20: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Enable CloudKit

Enabling CloudKit in Your Application

Page 21: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Introducing CloudKit API

!

Paul Seligman CloudKit Client Software

Page 22: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Page 23: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Page 24: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Page 25: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Page 26: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Records

Page 27: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Records

Record Zones

Page 28: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Records

Record Zones

Record Identifiers

Page 29: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Records

Record Zones

Record Identifiers

References

Page 30: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Records

Record Zones

Record Identifiers

References

Assets

Page 31: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Records

Record Zones

Record Identifiers

References

Assets

Page 32: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Containers

Page 33: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Containers

Page 34: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Containers

Page 35: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Containers

CKContainer

Page 36: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Containers

CKContainer

One container per app

Page 37: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Containers

CKContainer

One container per app

Data segregation

Page 38: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Containers

CKContainer

One container per app

Data segregation

User encapsulation

Page 39: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Containers

CKContainer

One container per app

Data segregation

User encapsulation

Managed by the developer

Page 40: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Containers

CKContainer

One container per app

Data segregation

User encapsulation

Managed by the developer• Managed via WWDR portal

Page 41: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Containers

CKContainer

One container per app

Data segregation

User encapsulation

Managed by the developer• Managed via WWDR portal

• Unique across all developers

Page 42: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Containers

CKContainer

One container per app

Data segregation

User encapsulation

Managed by the developer• Managed via WWDR portal

• Unique across all developers

Can be shared between apps

Page 43: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Records

Record Zones

Record Identifiers

References

Assets

Page 44: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Databases

Page 45: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Databases

CloudKit Container

PrivatePrivatePrivate

PrivatePrivatePrivate

PrivatePrivatePrivate

Public Database

Page 46: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Public Database

Databases

Private Database

CloudKit Container

Page 47: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Databases

Page 48: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Databases

CKDatabase

Page 49: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Databases

CKDatabase

Every app has access to two databases

Page 50: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Databases

CKDatabase

Every app has access to two databases• Public Database

Page 51: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Databases

CKDatabase

Every app has access to two databases• Public Database

• Private Database

Page 52: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKDatabase *publicDatabase = [[CKContainer defaultContainer] publicCloudDatabase]; !

CKDatabase *privateDatabase = [[CKContainer defaultContainer] privateCloudDatabase];

Databases

CKDatabase

Every app has access to two databases• Public Database

• Private Database

Page 53: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Databases

Public Database Private Database

Page 54: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Databases

Public Database Private Database

Data Type Shared Data Current User’s Data

Page 55: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Databases

Public Database Private Database

Data Type Shared Data Current User’s Data

Account Required for Writing Required

Page 56: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Databases

Public Database Private Database

Data Type Shared Data Current User’s Data

Account Required for Writing Required

Quota Developer User

Page 57: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Databases

Public Database Private Database

Data Type Shared Data Current User’s Data

Account Required for Writing Required

Quota Developer User

Default Permissions World Readable User Readable

Page 58: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Databases

Public Database Private Database

Data Type Shared Data Current User’s Data

Account Required for Writing Required

Quota Developer User

Default Permissions World Readable User Readable

Editing Permissions iCloud Dashboard Roles N/A

Page 59: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Records

Record Zones

Record Identifiers

References

Assets

Page 60: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Records

Public Database Private Database

CloudKit Container

Page 61: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Public Database

Records

Record

Record

Record

Record

Record

Record

Page 62: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Records

Page 63: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKRecord

Records

Page 64: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKRecord

Structured Data

Records

Page 65: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKRecord

Structured Data

Wraps key/value pairs

Records

Page 66: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKRecord

Structured Data

Wraps key/value pairs

Record Type

Records

Page 67: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKRecord

Structured Data

Wraps key/value pairs

Record Type

Just-in-time schema

Records

Page 68: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKRecord

Structured Data

Wraps key/value pairs

Record Type

Just-in-time schema

Metadata

Records

Page 69: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Values

Records

Page 70: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Values

Records

• NSString

• NSNumber

• NSData

• NSDate

Page 71: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Values

• CLLocation

Records

• NSString

• NSNumber

• NSData

• NSDate

Page 72: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Values

• CLLocation

Records

• CKReference

• CKAsset

• NSString

• NSNumber

• NSData

• NSDate

Page 73: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Values

• CLLocation

Records

• CKReference

• CKAsset

• Arrays of the above

• NSString

• NSNumber

• NSData

• NSDate

Page 74: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Records

Page 75: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Records

@interface CKRecord : NSObject <NSSecureCoding, NSCopying>

Page 76: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Records

@interface CKRecord : NSObject <NSSecureCoding, NSCopying>

- (instancetype)initWithRecordType:(NSString *)recordType;

Page 77: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Records

@interface CKRecord : NSObject <NSSecureCoding, NSCopying>

- (instancetype)initWithRecordType:(NSString *)recordType;

- (id)objectForKey:(NSString *)key; - (void)setObject:(id <CKRecordValue>)object forKey:(NSString *)key;

Page 78: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Records

@interface CKRecord : NSObject <NSSecureCoding, NSCopying>

- (instancetype)initWithRecordType:(NSString *)recordType;

- (id)objectForKey:(NSString *)key; - (void)setObject:(id <CKRecordValue>)object forKey:(NSString *)key;

- (id)objectForKeyedSubscript:(NSString *)key; - (void)setObject:(id <CKRecordValue>)object forKeyedSubscript:(NSString *)key;

Page 79: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Records

@interface CKRecord : NSObject <NSSecureCoding, NSCopying>

- (instancetype)initWithRecordType:(NSString *)recordType;

- (id)objectForKey:(NSString *)key; - (void)setObject:(id <CKRecordValue>)object forKey:(NSString *)key;

- (id)objectForKeyedSubscript:(NSString *)key; - (void)setObject:(id <CKRecordValue>)object forKeyedSubscript:(NSString *)key;

- (NSArray /* NSString */ *)allKeys;

Page 80: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Records

Page 81: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKRecord *party = [[CKRecord alloc] initWithRecordType:@“Party”];

Records

Page 82: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

// setting values [party setObject:@"Post Presentation Beers" forKey:@"summary"]; ! NSDate *startDate = [NSDate dateWithTimeIntervalSinceNow:30.0 * 60.0]; party[@"start"] = startDate;

CKRecord *party = [[CKRecord alloc] initWithRecordType:@“Party”];

Records

Page 83: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

// setting values [party setObject:@"Post Presentation Beers" forKey:@"summary"]; ! NSDate *startDate = [NSDate dateWithTimeIntervalSinceNow:30.0 * 60.0]; party[@"start"] = startDate;

CKRecord *party = [[CKRecord alloc] initWithRecordType:@“Party”];

Records

// accessing values NSString *summary = [party objectForKey:@"summary"]; ! NSDate *startDate = party[@"start"];

Page 84: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Records

Record Zones

Record Identifiers

References

Assets

Page 85: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Database

Record Zones

Record

Page 86: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Database

Record

Record Zones

Record Zone

RecordRecordRecordRecordRecordRecord

Page 87: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Database

Record Zone

Record Zones

RecordRecord

RecordRecord

RecordRecord

Record

Page 88: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Database

Record Zones

RecordRecord

Record

Default Zone Custom Zone

RecordRecord

Record

RecordRecord

Record

RecordRecord

Record

Page 89: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Records

Record Zones

Record Identifiers

References

Assets

Page 90: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Identifiers

Page 91: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Identifiers

@interface CKRecordID : NSObject <NSSecureCoding, NSCopying> ... @property (nonatomic, readonly, strong) NSString *recordName; @property (nonatomic, readonly, strong) CKRecordZoneID *zoneID; !@end

Page 92: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Identifiers

@interface CKRecordID : NSObject <NSSecureCoding, NSCopying> ... @property (nonatomic, readonly, strong) NSString *recordName; @property (nonatomic, readonly, strong) CKRecordZoneID *zoneID; !@end

• Created by the client

Page 93: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Identifiers

@interface CKRecordID : NSObject <NSSecureCoding, NSCopying> ... @property (nonatomic, readonly, strong) NSString *recordName; @property (nonatomic, readonly, strong) CKRecordZoneID *zoneID; !@end

• Created by the client

• Fully normalized: they represent the location of the record

Page 94: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Identifiers

@interface CKRecordID : NSObject <NSSecureCoding, NSCopying> ... @property (nonatomic, readonly, strong) NSString *recordName; @property (nonatomic, readonly, strong) CKRecordZoneID *zoneID; !@end

• Created by the client

• Fully normalized: they represent the location of the record

• External data set foreign key

Page 95: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Identifiers

Page 96: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Identifiers

CKRecord *party = [[CKRecord alloc] initWithRecordType:@“Party”];

Page 97: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Identifiers

CKRecord *party = [[CKRecord alloc] initWithRecordType:@“Party”];

@interface CKRecord : NSObject <NSSecureCoding, NSCopying> ... - (instancetype)initWithRecordType:(NSString *)recordType; - (instancetype)initWithRecordType:(NSString *)recordType recordID:(CKRecordID *)recordID; ... @end

Page 98: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Record Identifiers

CKRecord *party = [[CKRecord alloc] initWithRecordType:@“Party”];

@interface CKRecord : NSObject <NSSecureCoding, NSCopying> ... - (instancetype)initWithRecordType:(NSString *)recordType; - (instancetype)initWithRecordType:(NSString *)recordType recordID:(CKRecordID *)recordID; ... @end

CKRecordID *wellKnownID = [[CKRecordID alloc] initWithRecordName:@"WellKnownParty"]; CKRecord *party = [[CKRecord alloc] initWithRecordType:@"Party" recordID:wellKnownID];

Page 99: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Records

Record Zones

Record Identifiers

References

Assets

Page 100: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Public Database

References

Party

Party

Clown

Clown

Clown

Page 101: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Public Database

References

Party

Party

Clown

Clown

Clown

Page 102: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

References

Page 103: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKReference

References

Page 104: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKReference

Server Understands Relationship

References

Page 105: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKReference

Server Understands Relationship

Cascade Deletes

References

Page 106: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKReference

Server Understands Relationship

Cascade Deletes

Dangling Pointers

References

Page 107: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKReference

Server Understands Relationship

Cascade Deletes

Dangling Pointers

Back References

References

Page 108: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

References

Page 109: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKRecord *clown = [[CKRecord alloc] initWithRecordType:@“Clown”];

References

Page 110: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKRecord *clown = [[CKRecord alloc] initWithRecordType:@“Clown”];

References

CKRecord *party = [[CKRecord alloc] initWithRecordType:@“Party”]; CKReference *partyReference = [[CKReference alloc] initWithRecord:party action:CKReferenceActionNone]; clown[@"party"] = partyReference;

Page 111: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKRecord *clown = [[CKRecord alloc] initWithRecordType:@“Clown”];

References

CKRecord *party = [[CKRecord alloc] initWithRecordType:@“Party”]; CKReference *partyReference = [[CKReference alloc] initWithRecord:party action:CKReferenceActionNone]; clown[@"party"] = partyReference;

CKRecordID *wellKnownID = [[CKRecordID alloc] initWithRecordName:@"WellKnownParty"]; CKReference *wellKnownReference = [[CKReference alloc] initWithRecordID:wellKnownID action:CKReferenceActionNone]; clown[@"party"] = wellKnownReference;

Page 112: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Records

Record Zones

Record Identifiers

References

Assets

Page 113: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Assets

Public Database

Record

Record

Record

Record

Record

Record

Page 114: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Container

Public Database

Assets

Record

RecordPost

Presentation

Get Together

Page 115: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Assets

Container

Public Database Bulk Storage

Post

Presentation

Get Together

Record

Record

Page 116: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Assets

Container

Public Database Bulk Storage

Record

Record

CKRecord CKAsset

PPGT

Page 117: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Public Database

Assets

Container

Bulk Storage

Record

Record

PPGT

Page 118: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Assets

Page 119: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKAsset

Assets

Page 120: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKAsset

Large, unstructured data

Assets

Page 121: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKAsset

Large, unstructured data

Files on disk

Assets

Page 122: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKAsset

Large, unstructured data

Files on disk

Owned by CKRecords

Assets

Page 123: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKAsset

Large, unstructured data

Files on disk

Owned by CKRecords

Garbage collected

Assets

Page 124: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CKAsset

Large, unstructured data

Files on disk

Owned by CKRecords

Garbage collected

Efficient uploads and downloads

Assets

Page 125: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Assets

Page 126: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

NSURL *screenplayURL = [NSURL fileURLWithPath:@“...”]; ! CKAsset *screenplay = [[CKAsset alloc] initWithFileURL:screenplayURL];

Assets

Page 127: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

NSURL *screenplayURL = [NSURL fileURLWithPath:@“...”]; ! CKAsset *screenplay = [[CKAsset alloc] initWithFileURL:screenplayURL];

Assets

CKRecord *party = [[CKRecord alloc] initWithRecordType:@“Party”]; party[@"screenplay"] = screenplay;

Page 128: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fundamental CloudKit Objects

Containers

Databases

Records

Record Zones

Record Identifiers

References

Assets

Page 129: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CloudKit's Convenience API

Page 130: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Convenience API

Page 131: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Convenience API

Saving a record

Page 132: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Convenience API

Saving a record

Fetching a record

Page 133: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Convenience API

Saving a record

Fetching a record

Saving modified record

Page 134: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Convenience API

Saving a record

Fetching a record

Saving modified record

Page 135: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Saving a Record

Page 136: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Saving a Record

CKRecordID *wellKnownID = [[CKRecordID alloc] initWithRecordName:@"WellKnownParty"]; CKRecord *party = [[CKRecord alloc] initWithRecordType:@"Party" recordID:wellKnownID];

Page 137: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Saving a Record

CKRecordID *wellKnownID = [[CKRecordID alloc] initWithRecordName:@"WellKnownParty"]; CKRecord *party = [[CKRecord alloc] initWithRecordType:@"Party" recordID:wellKnownID];

CKDatabase *publicDatabase = [[CKContainer defaultContainer] publicCloudDatabase];

Page 138: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Saving a Record

CKRecordID *wellKnownID = [[CKRecordID alloc] initWithRecordName:@"WellKnownParty"]; CKRecord *party = [[CKRecord alloc] initWithRecordType:@"Party" recordID:wellKnownID];

CKDatabase *publicDatabase = [[CKContainer defaultContainer] publicCloudDatabase];

[publicDatabase saveRecord:party completionHandler:^(CKRecord *savedParty, NSError *error) { ! // appropriate error handling when (error != nil) }];

Page 139: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Convenience API

Saving a record

Fetching a record

Saving modified record

Page 140: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fetching a Record

Page 141: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fetching a Record

CKContainer *defaultContainer =[CKContainer defaultContainer]; CKDatabase *publicDatabase = [defaultContainer publicCloudDatabase];

Page 142: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Fetching a Record

CKContainer *defaultContainer =[CKContainer defaultContainer]; CKDatabase *publicDatabase = [defaultContainer publicCloudDatabase];

CKRecordID *wellKnownID = [[CKRecordID alloc] initWithRecordName:@"WellKnownParty"];

Page 143: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

[publicDatabase fetchRecordWithID:wellKnownID completionHandler:^(CKRecord *fetchedParty, NSError *error) { ! // truly marvelous error handling when (error != nil) }];

Fetching a Record

CKContainer *defaultContainer =[CKContainer defaultContainer]; CKDatabase *publicDatabase = [defaultContainer publicCloudDatabase];

CKRecordID *wellKnownID = [[CKRecordID alloc] initWithRecordName:@"WellKnownParty"];

Page 144: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Convenience API

Saving a record

Fetching a record

Saving modified record

Page 145: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Saving Modified Record

Page 146: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Saving Modified Record

CKDatabase *publicDatabase = ...; CKRecordID *wellKnownID = ...; [publicDatabase fetchRecordWithID:wellKnownID completionHandler:^(CKRecord *fetchedParty, NSError *error) { if (error) { ... } else {

Page 147: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Saving Modified Record

CKDatabase *publicDatabase = ...; CKRecordID *wellKnownID = ...; [publicDatabase fetchRecordWithID:wellKnownID completionHandler:^(CKRecord *fetchedParty, NSError *error) { if (error) { ... } else {

NSDate *endDate = fetchedParty[@"end"]; fetchedParty[@"end"] = [endDate dateByAddingTimeInterval:30.0 * 60.0];

Page 148: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Saving Modified Record

CKDatabase *publicDatabase = ...; CKRecordID *wellKnownID = ...; [publicDatabase fetchRecordWithID:wellKnownID completionHandler:^(CKRecord *fetchedParty, NSError *error) { if (error) { ... } else {

NSDate *endDate = fetchedParty[@"end"]; fetchedParty[@"end"] = [endDate dateByAddingTimeInterval:30.0 * 60.0];

[publicDatabase saveRecord:fetchedParty completionHandler:^(CKRecord *savedParty, NSError *saveError) { ! // error handling to make your mother proud when (error != nil) }]; } }];

Page 149: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Convenience API

Saving a record

Fetching a record

Saving modified record

Page 150: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Page 151: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Page 152: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Keep your large data in the cloud

Page 153: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Keep your large data in the cloud

Client views slice of that data

Page 154: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Keep your large data in the cloud

Client views slice of that data

Client view can change

Page 155: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Keep your large data in the cloud

Client views slice of that data

Client view can change

Clients use queries to focus their viewpoint

Page 156: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Queries

Page 157: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Queries

CKQuery

Page 158: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Queries

CKQuery

Combine a RecordType, a NSPredicate, and NSSortDescriptors

Page 159: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Queries

CKQuery

Combine a RecordType, a NSPredicate, and NSSortDescriptors• CloudKit supports a subset of NSPredicate

Page 160: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

QueriesPredicates

Page 161: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

QueriesPredicates

[NSPredicate predicateWithFormat:@"name = %@", partyName];

Page 162: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

QueriesPredicates

[NSPredicate predicateWithFormat:@"name = %@", partyName];

[NSPredicate predicateWithFormat:@"%K = %@", dynamicKey, value];

Page 163: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

QueriesPredicates

[NSPredicate predicateWithFormat:@"name = %@", partyName];

[NSPredicate predicateWithFormat:@"%K = %@", dynamicKey, value];

[NSPredicate predicateWithFormat:@"start > %@", [NSDate date]];

Page 164: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

QueriesPredicates

[NSPredicate predicateWithFormat:@"name = %@", partyName];

[NSPredicate predicateWithFormat:@"%K = %@", dynamicKey, value];

[NSPredicate predicateWithFormat:@"start > %@", [NSDate date]];

CLLocation *location = [[CLLocation alloc] initWithLatitude:37.783 longitude:-122.404]; [NSPredicate predicateWithFormat:@"distanceToLocation:fromLocation:(Location, %@) < 100", location];

Page 165: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

QueriesPredicates

[NSPredicate predicateWithFormat:@"name = %@", partyName];

[NSPredicate predicateWithFormat:@"%K = %@", dynamicKey, value];

[NSPredicate predicateWithFormat:@"start > %@", [NSDate date]];

CLLocation *location = [[CLLocation alloc] initWithLatitude:37.783 longitude:-122.404]; [NSPredicate predicateWithFormat:@"distanceToLocation:fromLocation:(Location, %@) < 100", location];

[NSPredicate predicateWithFormat:@"ALL tokenize(%@, 'Cdl') IN allTokens", @"after session"];

Page 166: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

QueriesPredicates

[NSPredicate predicateWithFormat:@"name = %@", partyName];

[NSPredicate predicateWithFormat:@"%K = %@", dynamicKey, value];

[NSPredicate predicateWithFormat:@"start > %@", [NSDate date]];

CLLocation *location = [[CLLocation alloc] initWithLatitude:37.783 longitude:-122.404]; [NSPredicate predicateWithFormat:@"distanceToLocation:fromLocation:(Location, %@) < 100", location];

[NSPredicate predicateWithFormat:@"ALL tokenize(%@, 'Cdl') IN allTokens", @"after session"];

[NSPredicate predicateWithFormat:@"name = %@ AND startDate > %@", partyName, [NSDate date]];

Page 167: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

QueriesCreating

NSPredicate *predicate = [NSPredicate predicateWithFormat: @"start > %@", [NSDate date]]; ! CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Party" predicate:predicate];

Page 168: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

QueriesPerforming

Page 169: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

QueriesPerforming

CKQuery *query = ...; ! [[publicDatabase performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error) {

Page 170: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

QueriesPerforming

CKQuery *query = ...; ! [[publicDatabase performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error) {

// astounding error handling when (error != nil) ! if (!error) { NSLog(@"Fetch %ld results", (long)[results count]); for (CKRecord *record in results) { NSLog(@"Found matching party %@", record); } } }];

Page 171: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Page 172: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Queries are polls

Page 173: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Queries are polls

Great for slicing through large server data

Page 174: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Queries are polls

Great for slicing through large server data

Bad for large, mostly static data set

Page 175: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Queries are polls

Great for slicing through large server data

Bad for large, mostly static data set• Battery life

Page 176: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Queries are polls

Great for slicing through large server data

Bad for large, mostly static data set• Battery life

• Networking traffic

Page 177: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Queries are polls

Great for slicing through large server data

Bad for large, mostly static data set• Battery life

• Networking traffic

• User experience

Page 178: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Queries are polls

Great for slicing through large server data

Bad for large, mostly static data set• Battery life

• Networking traffic

• User experience

What you want is the server running your query

Page 179: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Queries are polls

Great for slicing through large server data

Bad for large, mostly static data set• Battery life

• Networking traffic

• User experience

What you want is the server running your query• ... in the background

Page 180: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Queries are polls

Great for slicing through large server data

Bad for large, mostly static data set• Battery life

• Networking traffic

• User experience

What you want is the server running your query• ... in the background

• ... after every record save

Page 181: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Big Data, Tiny Phone

Queries are polls

Great for slicing through large server data

Bad for large, mostly static data set• Battery life

• Networking traffic

• User experience

What you want is the server running your query• ... in the background

• ... after every record save

• ... and you want push

Page 182: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

Page 183: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

CKSubscription

Page 184: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

CKSubscription

Combine a RecordType, a NSPredicate, and Push

Page 185: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

CKSubscription

Combine a RecordType, a NSPredicate, and Push• Push via Apple Push Service

Page 186: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

CKSubscription

Combine a RecordType, a NSPredicate, and Push• Push via Apple Push Service

• Augmented payload

Page 187: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

New parties In the future

Alert with "Party Time!"

SubscriptionsSubscriptionsNew parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

Page 188: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

New parties In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

Page 189: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

New parties In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

Page 190: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Party Tonight

E31970FB

Subscriptions

New parties In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

Page 191: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

Party Tonight

E31970FB

New parties In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

Page 192: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

Party Tonight

E31970FB

New parties In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

Page 193: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

Party Tonight

E31970FB

New parties In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

Page 194: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

Party Tonight

New parties In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

E31970FB

Page 195: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

Party Tonight

New parties In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

E31970FB

Page 196: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

Party Time!

Party Tonight

New parties In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

E31970FB

Page 197: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

Party Tonight

New parties In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

Party Time!E31970FB

Page 198: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Subscriptions

Party Tonight

New parties In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

New parties

In the future

Alert with "Party Time!"

Party Time!E31970FB

Page 199: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

SubscriptionsCreating

Page 200: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

SubscriptionsCreating

NSPredicate *predicate = [NSPredicate predicateWithFormat: @"start > %@", [NSDate date]];

Page 201: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

SubscriptionsCreating

NSPredicate *predicate = [NSPredicate predicateWithFormat: @"start > %@", [NSDate date]];

CKSubscription *subscription = [[CKSubscription alloc] initWithRecordType:@"Party" predicate:predicate options:CKSubscriptionOptionsFiresOnRecordCreation];

Page 202: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

SubscriptionsCreating

NSPredicate *predicate = [NSPredicate predicateWithFormat: @"start > %@", [NSDate date]];

CKSubscription *subscription = [[CKSubscription alloc] initWithRecordType:@"Party" predicate:predicate options:CKSubscriptionOptionsFiresOnRecordCreation];

CKNotificationInfo *notificationInfo = [CKNotificationInfo new]; notificationInfo.alertLocalizationKey = @"LOCAL_NOTIFICATION_KEY"; notificationInfo.soundName = @"Party.aiff"; notificationInfo.shouldBadge = YES;

Page 203: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

SubscriptionsCreating

NSPredicate *predicate = [NSPredicate predicateWithFormat: @"start > %@", [NSDate date]];

CKSubscription *subscription = [[CKSubscription alloc] initWithRecordType:@"Party" predicate:predicate options:CKSubscriptionOptionsFiresOnRecordCreation];

CKNotificationInfo *notificationInfo = [CKNotificationInfo new]; notificationInfo.alertLocalizationKey = @"LOCAL_NOTIFICATION_KEY"; notificationInfo.soundName = @"Party.aiff"; notificationInfo.shouldBadge = YES;

subscription.notificationInfo = notificationInfo;

Page 204: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

SubscriptionsSaving

CKSubscription *subscription = ...; ! [[publicDatabase saveSubscription:subscription completionHandler:^(CKSubscription *subscription, NSError *error) { ! // labor-of-love error handling when (error != nil) }];

Page 205: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

SubscriptionsHandling push

Page 206: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

SubscriptionsHandling push

@implementation AppDelegate ! - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

Page 207: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

SubscriptionsHandling push

@implementation AppDelegate ! - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

CKNotification *cloudKitNotification = [CKNotification notificationFromRemoteNotificationDictionary:userInfo];

Page 208: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

SubscriptionsHandling push

@implementation AppDelegate ! - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

CKNotification *cloudKitNotification = [CKNotification notificationFromRemoteNotificationDictionary:userInfo];

NSString *alertBody = cloudKitNotification.alertBody;

Page 209: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

SubscriptionsHandling push

@implementation AppDelegate ! - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

CKNotification *cloudKitNotification = [CKNotification notificationFromRemoteNotificationDictionary:userInfo];

NSString *alertBody = cloudKitNotification.alertBody;

if (cloudKitNotification.notificationType == CKNotificationTypeQuery) { CKQueryNotification *queryNotification = cloudKitNotification; CKRecordID *recordID = [queryNotification recordID]; } }

Page 210: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CloudKit User Accounts

Page 211: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CloudKit User Accounts

Page 212: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CloudKit User Accounts

Identity

Page 213: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CloudKit User Accounts

Identity

Metadata

Page 214: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CloudKit User Accounts

Identity

Metadata

Privacy

Page 215: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CloudKit User Accounts

Identity

Metadata

Privacy

Discovery

Page 216: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CloudKit User Accounts

Identity

Metadata

Privacy

Discovery

Page 217: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Identity

Container

Private Private

Private

Private

Private PrivatePrivate

PrivatePrivate

Page 218: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Identity

Container

Private Private

Private

Private

Private PrivatePrivate

PrivatePrivate

Page 219: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Identity

Container

Private Private

Private

Private

Private PrivatePrivate

PrivatePrivate

Page 220: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

[email protected]

[email protected]

[email protected]

[email protected]

[email protected]

Container

[email protected]

User Identity

Private

Private

Private

Private

Private

Private

Page 221: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Identity

Container

[email protected]

[email protected]

[email protected]

[email protected]

[email protected]

Private

Private

Private

Private

Private

[email protected]

Page 223: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

[email protected]

User Identity

[email protected]

[email protected]

[email protected]

[email protected]

Private

Private

Private

Private

Private

[email protected]

9ECDC8B9

Page 224: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

[email protected]

User Identity

[email protected]

[email protected]

[email protected]

[email protected]

Private

Private

Private

Private

Private

[email protected]

9ECDC8B9

Page 225: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

[email protected]

User Identity

[email protected]

[email protected]

[email protected]

[email protected]

Private

Private

Private

Private

Private

[email protected]

9ECDC8B9

50AD23DA

43183BD6

Page 226: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Identity

Page 227: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Identity

User Record ID

Page 228: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Identity

User Record ID

Stable identifier for this user

Page 229: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Identity

User Record ID

Stable identifier for this user

Scoped to the container

Page 230: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Identity

User Record ID

Stable identifier for this user

Scoped to the container

Independent API

Page 231: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Identity

[[CKContainer defaultContainer] fetchUserRecordIDWithCompletionHandler: ^(CKRecordID *userRecordID, NSError *error) { ! // ostentatious error handling when (error != nil) }];

Page 232: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CloudKit User Accounts

Identity

Metadata

Privacy

Discovery

Page 233: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

[email protected]

[email protected]

[email protected]

[email protected]

[email protected]

Private

Private

Private

Private

Private

[email protected]

9ECDC8B9

Page 234: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

Container

Public Database

User 9ECDC8B9

User 54C16AB7

User 4B20C8B2

User 843AE1DC

Private Database

User 9ECDC8B9

9ECDC8B9

Page 235: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

Container

Public Database

User 9ECDC8B9

User 54C16AB7

User 4B20C8B2

User 843AE1DC

Private Database

User 9ECDC8B9

9ECDC8B9

Page 236: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

User RecordContainer

Public Database

User 9ECDC8B9

User 54C16AB7

User 4B20C8B2

User 843AE1DC

Private Database

User 9ECDC8B9

9ECDC8B9

Page 237: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

User Record

One per database Container

Public Database

User 9ECDC8B9

User 54C16AB7

User 4B20C8B2

User 843AE1DC

Private Database

User 9ECDC8B9

9ECDC8B9

Page 238: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

User Record

One per database

World readable in public database

Container

Public Database

User 9ECDC8B9

User 54C16AB7

User 4B20C8B2

User 843AE1DC

Private Database

User 9ECDC8B9

9ECDC8B9

Page 239: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

User Record

One per database

World readable in public database

Treated like ordinary record

Container

Public Database

User 9ECDC8B9

User 54C16AB7

User 4B20C8B2

User 843AE1DC

Private Database

User 9ECDC8B9

9ECDC8B9

Page 240: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

User Record

One per database

World readable in public database

Treated like ordinary record• CKRecordTypeUserRecord

Container

Public Database

User 9ECDC8B9

User 54C16AB7

User 4B20C8B2

User 843AE1DC

Private Database

User 9ECDC8B9

9ECDC8B9

Page 241: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

User Record

One per database

World readable in public database

Treated like ordinary record• CKRecordTypeUserRecord

… mostly

Container

Public Database

User 9ECDC8B9

User 54C16AB7

User 4B20C8B2

User 843AE1DC

Private Database

User 9ECDC8B9

9ECDC8B9

Page 242: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

User Record

One per database

World readable in public database

Treated like ordinary record• CKRecordTypeUserRecord

… mostly• Reserved by system

Container

Public Database

User 9ECDC8B9

User 54C16AB7

User 4B20C8B2

User 843AE1DC

Private Database

User 9ECDC8B9

9ECDC8B9

Page 243: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

User Record

One per database

World readable in public database

Treated like ordinary record• CKRecordTypeUserRecord

… mostly• Reserved by system

• Cannot be queried

Container

Public Database

User 9ECDC8B9

User 54C16AB7

User 4B20C8B2

User 843AE1DC

Private Database

User 9ECDC8B9

9ECDC8B9

Page 244: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

CKContainer *defaultContainer =[CKContainer defaultContainer]; CKDatabase *publicDatabase = [defaultContainer publicCloudDatabase]; ! [defaultContainer fetchUserRecordIDWithCompletionHandler: ^(CKRecordID *userRecordID, NSError *error) { if (error) { ... } else {

Page 245: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

CKContainer *defaultContainer =[CKContainer defaultContainer]; CKDatabase *publicDatabase = [defaultContainer publicCloudDatabase]; ! [defaultContainer fetchUserRecordIDWithCompletionHandler: ^(CKRecordID *userRecordID, NSError *error) { if (error) { ... } else {

[publicDatabase fetchRecordWithID:userRecordID completionHandler:^(CKRecord *userRecord, NSError *error) {

Page 246: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Metadata

CKContainer *defaultContainer =[CKContainer defaultContainer]; CKDatabase *publicDatabase = [defaultContainer publicCloudDatabase]; ! [defaultContainer fetchUserRecordIDWithCompletionHandler: ^(CKRecordID *userRecordID, NSError *error) { if (error) { ... } else {

[publicDatabase fetchRecordWithID:userRecordID completionHandler:^(CKRecord *userRecord, NSError *error) {

if (error) { ... } else { NSString *partyName = userRecord[@"partyName"]; NSLog(@"Fetched record for %@:%@", partyName, userRecord); } }]; } }];

Page 247: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CloudKit User Accounts

Identity

Metadata

Privacy

Discovery

Page 248: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Privacy

Page 249: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Privacy

No disclosure by default

Page 250: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Privacy

No disclosure by default

Disclosure requested by application

Page 251: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Privacy

No disclosure by default

Disclosure requested by application

Page 252: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CloudKit User Accounts

Identity

Metadata

Privacy

Discovery

Page 263: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User DiscoveryEmail address

[email protected]

[email protected]

[email protected]

[email protected]

[email protected]@icloud.com

CloudKit

Client

Page 270: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User DiscoveryEntire address book

[email protected]

[email protected]

[email protected]

[email protected]

[email protected]

Client

Whole Address Book

CloudKit

Page 271: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User DiscoveryEntire address book

[email protected]

[email protected]

[email protected]

[email protected]

[email protected]

Client

Whole Address Book

CloudKit

Page 272: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User DiscoveryEntire address book

[email protected]

[email protected]

[email protected]

[email protected]

[email protected]

Client

CloudKit

Page 273: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User DiscoveryEntire address book

[email protected]

[email protected]

[email protected]

[email protected]

[email protected]

Client

CloudKit

Page 274: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User DiscoveryEntire address book

[email protected]

[email protected]

[email protected]

[email protected]

[email protected]

Client

CloudKit

Page 275: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User DiscoveryEntire address book

[email protected]

[email protected]

[email protected]

[email protected]

[email protected]

Client

CloudKit

Page 276: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User DiscoveryEntire address book

[email protected]

[email protected]

[email protected]

[email protected]

[email protected]

Client

CloudKit

Page 277: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User DiscoveryEntire address book

[email protected]

[email protected]

[email protected]

[email protected]

[email protected]

Client

CloudKit

Page 278: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Discovery

Input • User RecordID

• Email address

• Entire address book

Page 279: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Discovery

Input • User RecordID

• Email address

• Entire address book

Output

Page 280: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Discovery

Input • User RecordID

• Email address

• Entire address book

Output• User RecordID

Page 281: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Discovery

Input • User RecordID

• Email address

• Entire address book

Output• User RecordID

• First and last names

Page 282: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Discovery

Input • User RecordID

• Email address

• Entire address book

Output• User RecordID

• First and last names

Personally identifying information

Page 283: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Discovery

Input • User RecordID

• Email address

• Entire address book

Output• User RecordID

• First and last names

Personally identifying information• Requires opt-in

Page 284: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Discovery

CKContainer *defaultContainer = [CKContainer defaultContainer];

Page 285: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Discovery

CKContainer *defaultContainer = [CKContainer defaultContainer];

[defaultContainer discoverAllContactUserInfosWithCompletionHandler: ^(NSArray *userInfos, NSError *error) {

Page 286: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

User Discovery

CKContainer *defaultContainer = [CKContainer defaultContainer];

[defaultContainer discoverAllContactUserInfosWithCompletionHandler: ^(NSArray *userInfos, NSError *error) {

if (error) { ... } else { for (CKDiscoveredUserInfo *userInfo in userInfos) { NSLog(@"%@: %@ %@", userInfo.userRecordID, userInfo.firstName, userInfo.lastName); } } }];

Page 287: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

CloudKit User Accounts

Identity

Metadata

Privacy

Discovery

Page 288: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

When to Use CloudKit

Page 289: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

When to Use CloudKit

iCloud Key Value Store

iCloud Drive

iCloud Core Data

CloudKit

Page 290: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

When to Use CloudKit

iCloud Key Value Store

iCloud Drive

iCloud Core Data

CloudKit

• Asynchronously kept up to date

• Data limit constraints

• Great for application preferences

Page 291: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

When to Use CloudKit

iCloud Key Value Store

iCloud Drive

iCloud Core Data

CloudKit

• Simple API

• Full offline cache on OS X

• Unstructured

• Tied to the filesystem

• Great for document centric apps

Page 292: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

When to Use CloudKit

iCloud Key Value Store

iCloud Drive

iCloud Core Data

CloudKit

• Data replicated to all devices

• Data is single-user

• Great for keeping private, structured data in sync

Page 293: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

When to Use CloudKit

iCloud Key Value Store

iCloud Drive

iCloud Core Data

• Public data

• Structured and bulk data

• Large data set

• Use iCloud accounts

• Client directed data transfer

CloudKit

Page 294: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Summary

Page 295: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Summary

Access to iCloud servers

Page 296: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Summary

Access to iCloud servers

Public and private data

Page 297: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Summary

Access to iCloud servers

Public and private data

Structured and bulk data

Page 298: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Summary

Access to iCloud servers

Public and private data

Structured and bulk data

Leverage iCloud accounts

Page 299: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Summary

Access to iCloud servers

Public and private data

Structured and bulk data

Leverage iCloud accounts

Apple is building on it

Page 300: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Summary

Access to iCloud servers

Public and private data

Structured and bulk data

Leverage iCloud accounts

Apple is building on it

We're excited to see what you're going to build on this

Page 301: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

More Information

Dave DeLong App Frameworks Evangelist [email protected]

CloudKit Framework Reference http://developer.apple.com

Apple Developer Forums http://devforums.apple.com

Page 302: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Related Sessions

• Advanced CloudKit Mission Thursday 3:15PM

Page 303: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview

Labs

• CloudKit Lab Services Lab A Tuesday 4:30PM

• CloudKit Lab Frameworks Lab B Wednesday 12:45PM

• CloudKit Lab Frameworks Lab A Friday 11:30AM

Page 304: 208 CloudKit Intro Final DF - Apple Inc....Introduction to the API. Overview What is CloudKit Enabling CloudKit in your application Introduction to the API User Accounts. Overview