Acknowledged

Toybox.PersistedContent.Workout remove() API fails on device but works in simulator.

MonkeyVersion: [ 3, 1, 3 ]
Connect IQ SDK Version 4.1.6
device: 'Edge® 820 / Explore',
devicePartNum: '006-B2530-00',

Permission Granted to APP

  • Send/receive information to/from the Internet
  • Saved information such as courses, routes, waypoints, tracks or workouts

The following code function works in the simulator for the Edge 820. The function searches for a name in the Workouts PersistedContext. When the name is found
an attempt is made at removing the object. First a check is made to ensure that the remove() (symbol/function) exists before calling remove().

static function removeItem(generator as PersistedContent.Iterator, itemsArray as Array) {
    var item as PersistedContent.Content = generator.next();
    while (item != null) {
      if(itemsArray.indexOf(item.getName()) >= 0) {
        // Match found - so remove.
        try {
           System.println("Remove Item "+item.getName());
           // Backstop - can fail on some devices
           if (item has :remove) {
              System.println("Supports remove ");
              item.remove();
           }
        } catch (ex) {
           // Ignore error
           System.println("Invalid attempt at removing "+item.getName()+" Exception "+ex);
        }
     }
     item = generator.next();
    }
}
The function is called as:-
using Toybox.PersistedContent as PC;
System.println("Removing content "+itemsToDelete);
System.println("pcType = "+pcTypes[i]+" Items "+pcItems);
// Workouts
if (PC has :getWorkouts) {
    removeItem(PC.getWorkouts(),pcItems);
}
The content named in the pcItems dictionary is successfully removed in the simulator however it fails when run the actual device. 

The following logfile output is created on the Edge 820 device.

Removing content {W=>[Custom Target Values]}
pcType = W Items [Custom Target Values]
Remove Item Custom Target Values from W
Remove Item Custom Target Values
Supports remove
Invalid attempt at removing Custom Target Values Exception Obj: 189
So some type of exception is thrown

I have another function that lists the workout in the PC and this logs the following on the device:-
Searching for generic content
Item ID [329] Item Name = 1-All Options Cyc
Item ID [317] Item Name = Bike Workout
Item ID [273] Item Name = Custom Target Values
Item ID [242] Item Name = FITCycleCadence
So I can see that the items exists with ID 273 showing that the other APIs on the Toybox.PersistedContent work as expected (getId() and getName()).

Unfortunately I cannot see why the "remove()" API should fail on the actual device in this way.
Please can you have a look at this and let me know if you require further information.


 
  • This is working by design—PersistendContent.*.remove() methods can only remove content created/owned by the calling app. It will not work regardless of the API version (the methods won't be available on pre-3.x API products).

  • I have now added additional logging and find that the Exception is 

    "Invalid attempt at removing XXXXXX Exception Permission Denied: Content is not owned by this application"

    I was attempting to remove content that was initially on the device before my APP was installed. This can't happen in the simulator so hence there is a mismatch and the remove() function fails on the device. 

    Is it correct that the concept of "application owned content" was introduced in API version 3.0.0 with the introduction of the PC.getAPP*() style functions? Does this imply that the item.remove() method will work on all content on the device for API < 3.0.0 where the PC.getAPP*() functions don't exists (only the PC.get*() style do)?