Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CloudKit Web Services

CloudKit Web Services

Marcin Krzyzanowski

January 20, 2016
Tweet

More Decks by Marcin Krzyzanowski

Other Decks in Programming

Transcript

  1. ARCHITECTURE OVERVIEW CLOUDKIT ▸ Data store in a containers ▸

    Public and Private database ▸ Zones (default and custom) ▸ Records
  2. CLOUDKIT WEB SERVICES CLOUDKIT WEB SERVICES - WHAT IS THIS?

    ▸ JSON interface to CloudKit Server ▸ HTTP interface
  3. 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
  4. 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
  5. CLOUDKIT WEB SERVICES API - AUTHENTICATION ▸ OAuth ▸ CloudKit

    Dashboard ▸ Web Token - ckAPIToken ▸ Session key - ckSession
  6. CLOUDKIT WEB SERVICES SESSION KEY PARAMETER let charSet = NSCharacterSet(charactersInString:

    “+/=").invertedSet sessionToken.stringByAddingPercentEncodingWithAllowedCharacters(charSet)
  7. CLOUDKIT WEB SERVICES FETCHING RECORDS - REQUEST POST […]/[container]/[environment]/ [database]/records/query

    { "query" : { "recordType" : "NewsFeedItem" }, "zoneID" : { "zoneName" : "_defaultZone" } }
  8. 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" } } ] }
  9. CLOUDKIT WEB SERVICES IF LUCKY - BECAUSE OF ERRORS ▸

    22 HTTP error codes ▸ 500 for server fault ▸ 403 for unauthenticated requests ▸ 503 for retry
  10. CLOUDKIT WEB SERVICES ASK FOR MORE ▸ continuationMarker ▸ addition

    to the query parameters ▸ not retry - continuation ▸ Up to 100 records at once (tested)
  11. 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" } }
  12. 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
  13. CLOUDKIT WEB SERVICES ASSETS ▸ Up to 15 MB ▸

    Separate storage ▸ Temporary download URL ▸ Content-Type required POST […]/[container]/[environment]/[database]/assets/upload
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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