0

I use cocoalibspotify in an application and would like to get notified when a playlist is added or deleted.

I have tried adding an observer for the key path userPlaylists on the shared session but this does not seem to get called. I have also tried implementing the -sessionDidChangeMetadata: delete method but this seems to be only called when logging in.

Does anyone know how to get notified when the user adds or deletes a playlist?

simonbs
  • 7,932
  • 13
  • 69
  • 115

1 Answers1

1

You need to add a KVO observer to the playlists property of your session's userPlaylists container. You were adding your KVO one step too short. Note that the userPlaylists property will be nil for a short time after logging in, so you need to watch for that change too:

self.session = [SPSession sharedSession];
[self addObserver:self forKeyPath:@"session.userPlaylists.playlists" options:0 context:nil];
iKenndac
  • 18,730
  • 3
  • 35
  • 51
  • Something I have always worried about with KVO is passing zero as the option. Zero is outside the range of the constants defined in the NSKeyValueObservingOptions enum. The lowest value NSKeyValueObservingOptionNew has decimal value of 1. How does this affect the firing behaviour observer? – Daniel Farrell Feb 25 '13 at 00:04
  • I've been passing it for years with no problems. – iKenndac Feb 25 '13 at 12:20
  • Looking at the documentation for `NSKeyValueObservingOptions`, it says: "You can pass 0 if you require no change dictionary values." – iKenndac Feb 25 '13 at 12:29