I have encountered a weird problem with key value observing in iOS.
I have an object to which I add observers to monitor download progress:
[inAppProduct addObserver:self forKeyPath:@"progress" options:0 context:nil];
I then implement the method
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
Here the object
parameter contains the inAppProduct
which was changed. It all works well until the screen is locked during a download (either because of inactivity or manually by pressing the power button). After I unlock the screen the observer method still gets called every time inAppProduct
is updated, but the object
doesn't contain the new values. In stead it contains the last valueinAppProduct
had before the screen lock.
If I add the option NSKeyValueObservingOptionNew
while adding the observer the change
dictionary actually contains the new updated value, even though the object
doesn't.