从iOS应用发送新值时始终获取AppSync初始值 [英] Always getting AppSync initial values when sending new values from iOS app
问题描述
我正在为iOS应用程序创建一个Pebble伴侣应用程序.我已经用一些初始值设置了AppSync:
I am creating a Pebble companion app for an iOS application. I have setup my AppSync with some initial values:
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推送新数据时,初始值将设置为文本层,而不是发送的数据:
The problem is that when I push new data from my iPhone, the initial values are getting set to my text layers, instead of the data sent:
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端使用的代码:
This is the code I am using from the iPhone side:
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);
}
}];
我已经设置了观看按钮,以清除这些图层中的所有值,这就是我知道应用何时从手机获取更新的方式.
I have setup my watch buttons to clear out any values in those layers, this is how I know when the app is getting updates from the phone.
为什么AppSync持续使用旧数据,而不是新数据?
Why is AppSync continually using old data, instead of new data?
推荐答案
结果表明,多次调用app_sync_init
函数时,会表现出这种现象.由于某种原因,我在设置应用程序时曾两次被调用.一旦删除了多余的调用,我的回调将包含新数据,而不是初始数据.
Turns out this behavior is exhibited when calling the app_sync_init
function more than once. For some reason I had it being called twice when the application is being setup. Once I removed the extraneous call, my callbacks contained the new data, not the initial.
这篇关于从iOS应用发送新值时始终获取AppSync初始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!