Cli*_*rum 4 javascript cloudkit cloudkit-web-services cloudkit-js
我正在研究 Apple 的CloudKit Catalog 示例,我只是想让身份验证正常工作。我想在浏览器窗口(而不是 Node JS)中运行此 JS 代码。我从他们的网站上获取了他们的代码,如下所示:
\n\n<!DOCTYPE html>\n<html lang="en">\n <head></head>\n <body>\n <script>\n window.addEventListener(\'cloudkitloaded\', function() {\n\n CloudKit.configure({\n containers: [{\n containerIdentifier: \'iCloud.com.example.CloudKitCatalog\',\n apiToken: \'b86f0b5db29f04f45badba0366f39b7130a505f07765b5ba3a2ceb0cb3d96c0c\',\n persist: true,\n environment: \'production\',\n signInButton: { id: \'sign-in-button\', theme: \'black\' },\n signOutButton: { id: \'sign-out-button\', theme: \'black\' }\n }]\n })\n\n var container = CloudKit.getDefaultContainer()\n\n //-----\n function gotoAuthenticatedState(userIdentity) {\n var name = userIdentity.nameComponents\n if(name) {\n displayUserName(name.givenName + \' \' + name.familyName)\n } else {\n displayUserName(\'User record name: \' + userIdentity.userRecordName)\n }\n container\n .whenUserSignsOut()\n .then(gotoUnauthenticatedState)\n }\n\n //-----\n function gotoUnauthenticatedState(error) {\n if(error && error.ckErrorCode === \'AUTH_PERSIST_ERROR\') {\n showDialogForPersistError()\n }\n displayUserName(\'Unauthenticated User\')\n container\n .whenUserSignsIn()\n .then(gotoAuthenticatedState)\n .catch(gotoUnauthenticatedState)\n }\n\n // Check a user is signed in and render the appropriate button.\n return container.setUpAuth()\n .then(function(userIdentity) {\n // Either a sign-in or a sign-out button was added to the DOM.\n // userIdentity is the signed-in user or null.\n if(userIdentity) {\n gotoAuthenticatedState(userIdentity)\n } else {\n gotoUnauthenticatedState()\n }\n })\n\n })\n\n </script>\n\n <script src="https://cdn.apple-cloudkit.com/ck/2/cloudkit.js" async></script>\n\n <div id="sign-in-button"></div>\n <div id="sign-out-button"></div>\n</body>\n</html>\nRun Code Online (Sandbox Code Playgroud)\n\n但我不断收到这两个错误:
\n\ncloudkit.js:14 GET https://api.apple-cloudkit.com/database/1/iCloud.com.example.CloudKitCatalog/production/public/users/caller?ckjsBuildVersion=2005ProjectDev34&ckjsVersion=2.6.1&clientId=735f8b19-3218-4493-80e4-7ab0b39041ac 401 (Unauthorized)\n(anonymous) @ cloudkit.js:14\nRun Code Online (Sandbox Code Playgroud)\n\n紧接着...
\n\ncloudkit.js:14 Uncaught (in promise) t\xc2\xa0{\n _ckErrorCode: "AUTHENTICATION_FAILED", \n _uuid: "3b5cf33d-d56d-414f-83a4-6f320cd915b2", \n _reason: "no auth method found", \n _serverErrorCode: "AUTHENTICATION_FAILED", \n _extensionErrorCode: undefined,\xc2\xa0\xe2\x80\xa6\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我觉得这应该是简单的部分,但我什至无法让第一个setUpAuth()功能工作。我也尝试过我自己的 CloudKit containerIdentifier,apiToken但遇到了同样的错误。
有谁知道我做错了什么?
\n世界上似乎只有 5 个人了解 CloudKit JS API,而且他们都被重新分配到 ARKit 上工作,并且忽略了 Stack Overflow。;)
为了子孙后代,我知道我错了两件事。
== 1 ==
您必须忽略弃用警告并使用版本 1 JS 文件 ( ck/1/cloudkit.js):
https://cdn.apple-cloudkit.com/ck/1/cloudkit.js
Run Code Online (Sandbox Code Playgroud)
== 2 ==
不管文档如何规定,您实际上无法<div id="">在容器配置中指定身份验证按钮。当我将 HTML 更改为使用默认 Apple ID 时,“登录”按钮开始出现<div>:
<div id="apple-sign-in-button"></div>
<div id="apple-sign-out-button"></div>
Run Code Online (Sandbox Code Playgroud)
我希望这对其他人有帮助。:)
| 归档时间: |
|
| 查看次数: |
807 次 |
| 最近记录: |