我正在创建一个基于 cocoaLibSpotify 的 IOS 应用程序。
在某些时候,我正在从一系列歌曲中创建一个 Spotify 播放列表。我之前已经获得了所有的 Spotify URI,然后我创建了播放列表并一一添加了所有曲目。
下面的代码在应用程序的逻辑类中,然后我有一个控制器来显示结果。问题是我从控制器调用此逻辑,但我不知道添加过程完成后返回的方法。我试图实现一个委托,但我不知道该怎么做......
将曲目添加到播放列表的正确方法是什么?我一直在搜索文档和 GitHub 存储库,但我只找到了一个带有两个嵌套轨道添加的示例......:S
提前致谢!(对不起我的英语)
- (void) createPlaylist:(NSArray*)spotifyURIs withName:(NSString*)name {
    int songsRead = 0;
    [container createPlaylistWithName:name callback:^(SPPlaylist *createdPlaylist) {
        [SPAsyncLoading waitUntilLoaded:createdPlaylist timeout:kSPAsyncLoadingDefaultTimeout then:^(NSArray *loadedPlaylist, NSArray *notLoadedPlaylist) {
            for (int i=[spotifyURIs count]-1; i>=0; i--) {
                NSString *trackURI = spotifyURIs[i];
                if (trackURI != nil){
                    [[SPSession sharedSession] trackForURL:[NSURL URLWithString:trackURI] callback:^(SPTrack *track) {
                        if (track != nil) {
                            [createdPlaylist addItems:[NSArray arrayWithObject: track] atIndex:[[createdPlaylist items] count] callback:nil];
                        }
                    }];
                }
                songsRead++;
                // If I have read the whole tracklist, end of the process, returning to controller...
                if (songsRead == [spotifyURIs count]){
                    // ...
                }
            }
        }];
    }];
}