我在将新创建的SPPlaylist
移动到(可能是新创建的)SPPlaylistFolder
时遇到问题。将播放列表移动到文件夹不起作用
这个想法是在用户的Spotify帐户中创建一个文件夹,我可以在其中添加从我的应用程序生成的播放列表。如果没有创建这样的文件夹,我将创建一个新的SPPlaylistFolder
并保存该文件夹ID供以后使用。
这是我在做什么(我省略了那些不感兴趣的这个问题的部分代码):
如果
folderId
先前已保存(即文件夹中创建) ,使用该ID来加载该文件夹实例:... NSError *error = nil; if (folderId > 0) { // try to fetch folder folder = [[SPSession sharedSession] playlistFolderForFolderId:folderId inContainer:container]; } if (folder == nil) { // create folder folder = [container createFolderWithName:@"My Folder" error:&error]; // save a reference to the folder in an instance var _appFolder = [folder retain]; // (also saving folder.folderId in NSUserDefaults) } ...
创建
SPPlaylist
:[[[SPSession sharedSession] userPlaylists] createPlaylistWithName:@"My Playlist"]
。使用KVO观察容器的
playlists
属性,并在播放列表创建时得到通知:[[[SPSession sharedSession] userPlaylists] addObserver:self forKeyPath:@"playlists" options:0 context:nil]
。观察
playlists
财产和移动创建的播放列表到我的SPPlaylistFolder
(containerPlaylist
是我已经确定为一个移动的播放列表):... // identify the index of the containerPlaylist NSInteger playlistIndex = [[[[SPSession sharedSession] userPlaylists] playlists] indexOfObject:containerPlaylist]; // move playlist NSError * error = nil; BOOL success = [container movePlaylistOrFolderAtIndex:playlistIndex ofParent:nil toIndex:0 ofNewParent:_appFolder error:&error]; if (success) { // This should be a great success. But the playlist hasn't been moved, although the error variable is nil. } ...
这些步骤之后,无论是播放列表和文件夹已创建,但播放列表尚未移动。而且我没有收到任何错误,指示movePlaylistOrFolderAtIndex
方法的任何无效输入。
我在这里错过了一些明显的东西吗?或者,移动功能是否有缺陷?
注意:我也尝试使用此代码移动先前创建的播放列表(即将名为“My Playlist”的所有播放列表移动到文件夹中)。
编辑1:我已经调查了这一点,实际上得到了一些正在进行的动作。但是我不得不重写一些代码并执行几次(或稍后阶段)的移动。看起来这与SPSession中的数据不完全同步/最新(?)有关,因为可能在以后使用新会话记录时移动播放列表。
它可能是同步问题,即libspotify认为SPPlaylistFolder
已创建并将SPPlaylist
s移动到它,但实际上尚未创建它?