我正尝试使用node.js和Apple的CloudKit.js与我的CloudKit数据库进行交互。我成功地创建了一个服务器到服务器的密钥,我可以使用该程序添加,删除或编辑记录。添加订阅也有效。现在,我希望它收到通知时会收到通知并打印一行。但是,启用通知失败了。我正在尝试注册的回调函数也没有被调用。CloudKit JS通过节点:无法注册通知
无论我多久打电话给我的容器上的registerForNotifications()
,在打印属性isRegisteredForNotifications
时,我总是收到false
。
我来自一个关于编程语言的“桌面/移动/本地/嵌入”为中心的背景,所以node.js,JavaScript的承诺,尤其是.then()
的语法对我来说还是有点陌生。
这是我想用来接收通知的代码:
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var fetch = require('node-fetch');
var CloudKit = require('./cloudkit');
var containerConfig = require('./config');
// A utility function for printing results to the console.
var println = function(key,value) {
console.log("--> " + key + ":");
console.log(value);
console.log();
};
//CloudKit configuration
CloudKit.configure({
services: {
fetch: fetch,
logger: console
},
containers: [ containerConfig ]
});
var container = CloudKit.getDefaultContainer();
var database = container.publicCloudDatabase; // We'll only make calls to the public database.
// Sign in using the keyID and public key file.
container.setUpAuth();
function renderNotification(notification) {
console.log('Got notification!')
};
CloudKit.getDefaultContainer().registerForNotifications();
CloudKit.getDefaultContainer().addNotificationListener(renderNotification);
console.log(CloudKit.getDefaultContainer().isRegisteredForNotifications); // Why does this print false?
即使推出新的订阅和添加使用.then()
回调,这就要求addNotificationListener
,物业还称false
和renderNotification
永远不会调用。
这是Apple的CloudKit JS中的错误还是我做错了什么?
此外,我想提一提,我能够使用我用Python封装的JSON API(here)成功完成相同的任务(创建,编辑,删除记录或订阅)。但是,似乎没有办法接收订阅通知,这就是为什么我想在这里使用node.js和Apple的CloudKit.js。如果我在这里丢失了一些东西,并且接收通知实际上可能既不使用CloudKit.js也不使用Cocoa API,我会很乐意接受有关如何执行此操作的任何建议。
感谢您的帮助!
有一个错误:{[错误:找不到验证方法] _ckErrorCode:'AUTHENTICATION_FAILED',嗯现在什么? – malhal