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

CloudKit Web Services

CloudKit Web Services

7b2fdba8077c8495b3caa6f36d0928da?s=128

Marcin Krzyzanowski

January 20, 2016
Tweet

Transcript

  1. CLOUDKIT WEB SERVICES MARCIN KRZYŻANOWSKI, BERLIN 20.01.2016

  2. WELCOME Marcin Krzyżanowski @krzyzanowskim krzyzanowskim.com github.com/krzyzanowskim

  3. WELCOME CryptoSwift ObjectivePGP Natalie Storyboard Generator github.com/krzyzanowskim

  4. CLOUDKIT WEB SERVICES AGENDA ▸ Architecture overview ▸ Use case

    ▸ API
  5. ARCHITECTURE OVERVIEW CLOUDKIT ▸ Data store in a containers ▸

    Public and Private database ▸ Zones (default and custom) ▸ Records
  6. ARCHITECTURE OVERVIEW CLOUDKIT ▸ CloudKit Server ▸ Native CloudKit.framework ▸

    CloudKit Web Services
  7. CLOUDKIT WEB SERVICES CLOUDKIT WEB SERVICES - WHAT IS THIS?

    ▸ JSON interface to CloudKit Server ▸ HTTP interface
  8. 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
  9. CLOUDKIT WEB SERVICES ▸ Parse #not ▸ Azure #not ▸

    iCloud #yes
  10. HANDLING CLOUDKIT RIGHT IS HARDER THAN HANDLING COREDATA RIGHT Stève

    Jöbs #never CLOUDKIT WEB SERVICES
  11. USE CASE CLOUDKIT WEB SERVICES

  12. None
  13. ▸ iOS Client Application ▸ OSX Content Management Application

  14. REQUIRE MAC APP STORE FOR PRODUCTION DATABASE

  15. None
  16. REQUIRE MAC APP STORE FOR PRODUCTION DATABASE

  17. 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
  18. CLOUDKIT WEB SERVICES API - AUTHENTICATION ▸ OAuth ▸ CloudKit

    Dashboard ▸ Web Token - ckAPIToken ▸ Session key - ckSession
  19. CLOUDKIT WEB SERVICES https://api.apple-cloudkit.com/database/v1/[container]/ [production]/[operation-specific subpath]?ckAPIToken=[API token]&ckSession=[session] URL

  20. CLOUDKIT WEB SERVICES SESSION KEY PARAMETER let charSet = NSCharacterSet(charactersInString:

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

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

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

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

    Separate storage ▸ Temporary download URL ▸ Content-Type required POST […]/[container]/[environment]/[database]/assets/upload
  28. 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
  29. 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
  30. 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
  31. 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
  32. 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
  33. THANK YOU Marcin Krzyżanowski @krzyzanowskim krzyzanowskim.com github.com/krzyzanowskim