Share
Embed
CloudKit Web Services
Marcin Krzyzanowski
January 20, 2016
Transcript
33 slides
-
ARCHITECTURE OVERVIEW CLOUDKIT ▸ Data store in a containers ▸
Public and Private database ▸ Zones (default and custom) ▸ Records -
ARCHITECTURE OVERVIEW CLOUDKIT ▸ CloudKit Server ▸ Native CloudKit.framework ▸
CloudKit Web Services -
CLOUDKIT WEB SERVICES CLOUDKIT WEB SERVICES - WHAT IS THIS?
▸ JSON interface to CloudKit Server ▸ HTTP interface -
CLOUDKIT WEB SERVICES FEATURES ▸ Access to Public and Private
containers ▸ CRUD (create, read, update, delete) records ▸ Upload and downlod Assets ▸ User discoverability ▸ Web companion to native framework -
HANDLING CLOUDKIT RIGHT IS HARDER THAN HANDLING COREDATA RIGHT Stève
Jöbs #never CLOUDKIT WEB SERVICES -
CLOUDKIT WEB SERVICES HOW IT IS? ▸ Seems to work
in general ▸ Well documented ▸ Quite easy to understand ▸ StackOverflow is not helpful ▸ Hardly anybody is using it -
CLOUDKIT WEB SERVICES API - AUTHENTICATION ▸ OAuth ▸ CloudKit
Dashboard ▸ Web Token - ckAPIToken ▸ Session key - ckSession -
CLOUDKIT WEB SERVICES SESSION KEY PARAMETER let charSet = NSCharacterSet(charactersInString:
“+/=").invertedSet sessionToken.stringByAddingPercentEncodingWithAllowedCharacters(charSet) -
CLOUDKIT WEB SERVICES FETCHING RECORDS - REQUEST POST […]/[container]/[environment]/ [database]/records/query
{ "query" : { "recordType" : "NewsFeedItem" }, "zoneID" : { "zoneName" : "_defaultZone" } } -
CLOUDKIT WEB SERVICES FETCHING RECORDS - RESPONSE POST […]/[container]/[environment]/ [database]/records/query
{ "records": [ { "created": { "deviceID": "2", "timestamp": 1452769506019, "userRecordName": "_de35cbe145f780b85996c675811e7aa7" }, "fields": { "title": { "type": "STRING", "value": "Berlin meetup" } }, "modified": { "deviceID": "2", "timestamp": 1452769506019, "userRecordName": "_de35cbe145f780b85996c675811e7aa7" }, "recordChangeTag": "ije5gd0j", "recordName": "08F420AC-74A5-4408-8A92-C00E980FC74E", "recordType": "NewsFeedItem", "zoneID": { "zoneName": "_defaultZone" } } ] } -
CLOUDKIT WEB SERVICES IF LUCKY - BECAUSE OF ERRORS ▸
22 HTTP error codes ▸ 500 for server fault ▸ 403 for unauthenticated requests ▸ 503 for retry -
CLOUDKIT WEB SERVICES ASK FOR MORE ▸ continuationMarker ▸ addition
to the query parameters ▸ not retry - continuation ▸ Up to 100 records at once (tested) -
CLOUDKIT WEB SERVICES BUILDING QUERY ▸ ___modTime ▸ ___createTime {
"query" : { "recordType" : "NewsFeedItem", "filterBy" : [ { "fieldName" : "___modTime", "comparator" : "GREATER_THAN_OR_EQUALS", "fieldValue" : { "value" : 1453058445252, "type" : "TIMESTAMP" } } ] }, "zoneID" : { "zoneName" : "_defaultZone" } } -
CLOUDKIT WEB SERVICES PARSING VALUES ▸ REFERENCE - is a
link type to a record ▸ DOUBLE and INT64 are numbers ▸ BYTES is Base64 encoded array of bytes ▸ TIMESTAMP is for dates and times in seconds ▸ STRING is string obviously ▸ ASSETID is for assets. Assets are stored separately to the database itself. ▸ REFERENCE_LIST ▸ DOUBLE_LIST ▸ INT64_LIST ▸ BYTES_LIST ▸ TIMESTAMP_LIST ▸ STRING_LIST ▸ ASSETID_LIST -
CLOUDKIT WEB SERVICES ASSETS ▸ Up to 15 MB ▸
Separate storage ▸ Temporary download URL ▸ Content-Type required POST […]/[container]/[environment]/[database]/assets/upload -
CLOUDKIT WEB SERVICES MODIFY RECORDS ▸ 7 operations ▸ force*
to ignore conflicts ▸ delete non-existing record POST […]/[container]/[environment]/[database]/records/modify ▸ create ▸ update ▸ forceUpdate ▸ replace ▸ forceReplace ▸ delete ▸ forceDelete -
CLOUDKIT WEB SERVICES MODIFY RECORDS ▸ 7 operations ▸ force*
to ignore conflicts ▸ delete non-existing record ▸ little delay POST […]/[container]/[environment]/[database]/records/modify ▸ create ▸ update ▸ forceUpdate ▸ replace ▸ forceReplace ▸ delete ▸ forceDelete -
CLOUDKIT WEB SERVICES MODIFY RECORDS ▸ 7 operations ▸ force*
to ignore conflicts ▸ delete non-existing record ▸ little delay ▸ ASSETID_LIST problem POST […]/[container]/[environment]/[database]/records/modify ▸ create ▸ update ▸ forceUpdate ▸ replace ▸ forceReplace ▸ delete ▸ forceDelete -
CLOUDKIT WEB SERVICES THERE IS MORE ▸ Creating new custom
zones ▸ Manage subscriptions (query subscriptions) ▸ Fetch user data ▸ Find users ▸ https://developer.apple.com/library/ios/documentation/DataManagement/ Conceptual/CloutKitWebServicesReference ▸ CloudKit JS -
CLOUDKIT WEB SERVICES RECAP ▸ CloudKit architecture (private/public/ development/production) ▸
CloudKit Web Services allows you to deal with the CloudKit data without App Store ▸ Real life use case ▸ API details