我已按照 pebble 表盘的教程进行操作,但更改了一些内容,但在日志中收到错误:
忽略无效 key :KEY_TEMPERATURE 忽略无效 key :KEY_CONDITIONS
这导致没有显示天气,我认为这可能是 js 代码,但我已经在教程 main.c 上使用了它,并且工作正常。
最佳答案
您没有在 appinfo.json
中指定任何 appKeys
。
Pebble 消息使用整数作为键控,而不是字符串。但是有适当的设施,所以您可以 use meaningful strings when coding :
Using Named Keys in PebbleKit JS Messages
PebbleKit JavaScript provides a mechanism to use named keys instead of integer keys. This improves the readability of your JavaScript code and allows you to group in one place the definition of your AppMessage keys.
Keys are declared in CloudPebble in the 'PebbleKit JS Message Keys' section of the 'Settings' screen.
In the native SDK, named keys are configured through the
appKeys
object in theappinfo.json
file. This object associates integer values to strings. Those values are used to convert the keys of outgoing and incoming messages."appKeys": { "firstKey": 0, "secondKey": 1 }
请注意,此处定义的键应与 C 代码中的键匹配,可能是通过 C 源代码或头文件中的 #define
语句实现的。
For each key of an incoming message, PebbleKit JS looks for an element in the
appKeys
object that has the same integer value as the key. If it can find one, it replaces this key by this string in the JavaScript object. If it cannot find one, it creates a new string containing the integer value of the key.For each key of an outgoing message, PebbleKit JS looks for an element in the
appKeys
object that is equal to the key. If it finds one, it uses the integer value associated with this element as the integer representation of the key. If it cannot find one, it tries to convert the key into an integer. If this fails, an error is raised.For example, given the
appKeys
configuration above, the following statements are equivalent:Pebble.sendAppMessage({ '0': 'A value' }); Pebble.sendAppMessage({ 'firstKey': 'A value' });
确保更新您的代码,以便在 C 中指定这些值(您似乎是通过 #define
完成的)以及 JavaScript 中通过appinfo.json
文件:
...
"appKeys": {
"KEY_TEMPERATURE": 0,
"KEY_CONDITIONS": 1
},
...
关于c - pebble watch 上出现 "Ignoring invalid key: KEY_TEMPERATURE"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28014969/