So, what you need is for your widget code to get notified when the user uses Settings (Preferences.app) to change a setting. Based on the way your plist is setup, it looks like a Darwin notification named
dylankelly.MyStat-preferencesChanged
will be sent through the Darwin notification center, when the user has changed the setting. So, you need to register a callback to be invoked when this notification occurs. As soon as your code is loaded, you should do something like this (for example, in MyWidgetViewController.m, if that's where the image views are managed):
#include <notify.h>
...
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
(void*)self, // observer
onPreferencesChanged, // callback
CFSTR("dylankelly.MyStat-preferencesChanged"), // event name
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
where your callback method (put this in the same MyWidgetViewController.m file) would be:
static void onPreferencesChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
// since this is a static method, we pass the instance in the observer parameter
MyWidgetViewController* vc = (MyWidgetViewController*)observer;
[vc updateImage];
}
and finally, the code to read the preference plist and update your image view:
-(void) updateImage {
// load the preferences plist file, and read the new color_pref value
NSDictionary* sharedPrefs = [[NSDictionary alloc] initWithContentsOfFile: PLIST_FILENAME];
NSNumber* color = (NSNumber*)[sharedPrefs valueForKey: @"color_pref"];
int colorValue = [color intValue];
// the integer values correspond to the validValues defined in the
// preference bundle's plist file
switch (colorValue) {
case 1:
bgView.image = [UIImage imageNamed: @"blueBackground"]; // for blueBackground.png / blueBackground@2x.png
break;
case 2:
bgView.image = [UIImage imageNamed: @"greenBackground"];
break;
case 3:
bgView.image = [UIImage imageNamed: @"redBackground"];
break;
default:
break;
}
}