获取CloudKit CKAsset URL?

时间:2015-12-01 12:44:50

标签: ios swift icloud cloudkit cloudkit-web-services

我想与不使用我的应用的人共享公共数据库中的CloudKit资产。在CKAsset类中,只有fileURL属性,它指向本地文件,因此没有给出URL。

但是,在CloudKit Web服务的文档there is a "referencing existing assets" request上,in its' response为资产文件提供了downloadURL

从我的应用程序调用此代码会为我提供421状态代码,其中in documentation描述为" AUTHENTICATION_REQUIRED",因为它需要提供ckSession参数,这是一个"经过身份验证的用户的会话标识符"。它还传递redirectURL,用户可以在其中输入他们的iCloud登录信息,然后重新定向回Web应用程序,现在使用会话标识符。

在应用程序内打开此URL并不会立即返回会话标识符,而是希望用户在收到会话ID之前在浏览器中完成登录过程。

这似乎完全偏离轨道,而且做错了。我当然不会让我的用户通过网络界面登录iCloud。 CloudKit Web Services URL唯一缺少的是会话ID。有没有办法让我使用CloudKit框架?或者我有另一种方法可以找到这个文件的URL吗?

1 个答案:

答案 0 :(得分:0)

如果您使用的是Apple官方CloudKit.js,以下是配置CloudKit访问权限的代码:

window.addEventListener('cloudkitloaded', function() {
  console.log('Cloudkit loaded');
  CloudKit.configure({
    locale: 'en-us',
    containers: [{
      containerIdentifier: 'iCloud.com.getYoursInXcode',
      apiTokenAuth: {
        apiToken: 'getThisInCloudkitDashboardApiAccess',
        persist: true //Set cookie
      },
      environment: 'production'
    }]
  });
  // Do your thing here

  })

如果要在后端获取记录,最好是获取API令牌而不是使用“服务器到服务器”进程。 例如,在GO中查询记录以获取记录,就像这样构建您的请求体

sampleRequest = []byte('{
        "resultsLimit":"4",
        "desiredKeys": ["recordTitle","recordDescription"],
        "query": {
        "recordType": "myRecord",
        "sortBy": {
        "fieldName": "rank",
        "ascending": true
    }
    }
        }')

并将其发送到以下网址

http.NewRequest("POST", ""https://api.apple-cloudkit.com/database/1/iCloud.com.yourIdentifier/production/public/records/query?ckAPIToken=YOURTOKEN", bytes.NewBuffer(RequestBody))
相关问题