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.
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
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.
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.