我正在为 iOS 应用程序创建 Pebble 配套应用程序。我已经用一些初始值设置了我的 AppSync:
Tuplet initial_values[] = {
TupletCString(SYNC_KEY_LANGUAGE, language),
TupletCString(SYNC_KEY_TOTAL_AMOUNT, totalAmount),
TupletCString(SYNC_KEY_TODAY_AMOUNT, todayAmount),
TupletCString(SYNC_KEY_TRIP_NAME, tripName)
};
app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values,
ARRAY_LENGTH(initial_values), sync_tuple_changed_callback,
sync_error_callback, NULL);
问题是,当我从 iPhone 推送新数据时,初始值被设置为我的文本层,而不是发送的数据:
static void sync_tuple_changed_callback(const uint32_t key, const Tuple* new_tuple, const Tuple* old_tuple, void* context) {
switch (key) {
case SYNC_KEY_TRIP_NAME: {
text_layer_set_text(tripNameLayer, new_tuple->value->cstring);
layer_mark_dirty((Layer *)tripNameLayer);
}
break;
case SYNC_KEY_TOTAL_AMOUNT: {
text_layer_set_text(totalAmountLayer, new_tuple->value->cstring);
layer_mark_dirty((Layer *)totalAmountLayer);
}
break;
case SYNC_KEY_TODAY_AMOUNT: {
text_layer_set_text(todayAmountLayer, new_tuple->value->cstring);
layer_mark_dirty((Layer *)todayAmountLayer);
//storeData(STORAGE_KEY_TODAY_AMOUNT, (char *)new_tuple->value->cstring);
}
break;
case SYNC_KEY_LANGUAGE: {
// DO NOTHING
}
break;
default: {
debugMessage("default case");
}
break;
}
}
这是我在 iPhone 端使用的代码:
NSDictionary *tripInfo = @{
@(SyncKeyTripName) : @"Denver",
@(SyncKeyLanguage) : @"en",
@(SyncKeyTotalAmount) : @"154.43",
@(SyncKeyTodayAmount) : @"23.50"
};
[self.watch appMessagesPushUpdate:tripInfo
onSent:^(PBWatch *watch, NSDictionary *update, NSError *error) {
if (error) {
NSLog(@"error sending update! %@", error);
} else {
NSLog(@"update: %@", update);
}
}];
我已经设置了我的手表按钮以清除这些层中的任何值,这就是我知道应用程序何时从手机获取更新的方式。
为什么 AppSync 不断地使用旧数据而不是新数据?