Always getting AppSync initial values when sending new values from iOS app

StackOverflow https://stackoverflow.com/questions/22753946

  •  24-06-2023
  •  | 
  •  

سؤال

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);

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;
    }
}

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.

Why is AppSync continually using old data, instead of new data?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top