0

Is it possible to synchronize a UITextView within an iPhone application with a text layer on my Pebble?

I just want to display a String on a Pebble watch.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
MappleDev
  • 453
  • 1
  • 6
  • 11

1 Answers1

1

This can be done using the AppSync API, which is built on top of AppMessage specifically to provide a system suitable for UI synchronization. The following example is taken from the AppSync section in this official guide and shows the watchapp side of things:

  1. To synchronize watch fields, your app needs to declare the input and output buffer sizes in bytes.

    const int inbound_size = 64;
    const int outbound_size = 64;
    app_message_open(inbound_size, outbound_size);
    
  2. Prepare the initial values of your data.

    Tuplet initial_values[] = {
      TupletInteger(WEATHER_ICON_KEY, (uint8_t) 1),
      TupletCString(WEATHER_TEMPERATURE_KEY, "42°C"),
    };
    
  3. Reserve global memory to store an AppSync struct and your Dictionary.

    #include <...>
    
    AppSync sync;
    uint8_t sync_buffer[32];
    
  4. Initialize the synchronization.

    app_sync_init(&sync, sync_buffer, sizeof(sync_buffer),
                  initial_values, ARRAY_LENGTH(initial_values),
                  sync_tuple_changed_callback, sync_error_callback, NULL);
    
  5. Process the first and subsequent update.

    void sync_tuple_changed_callback(const uint32_t key,
           const Tuple* new_tuple, const Tuple* old_tuple, void* context)
    {
      // Update your layers
      // Don't forget to call layer_mark_dirty()
    }
    
  6. Finally, you can update the value on the watch side. The callback is called when the app has been acknowledged.

    Tuplet new_tuples[] = {
      TupletInteger(WEATHER_ICON_KEY, (uint8_t) 3),
      TupletCString(WEATHER_TEMPERATURE_KEY, "73°C"),
    };
    
    app_sync_set(&sync, new_tuples, 2);
    

I'm not an iOS developer, so I can't help you much on the Objective C side of things, but the article I linked above suggests reading the iOS WeatherDemo app that ships with the SDK for a complete example.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257