gpt4 book ai didi

ios - Spotify iOS-SDK : Get Tracks from Playlist returns (null) Tracks

转载 作者:行者123 更新时间:2023-11-28 21:20:36 29 4
gpt4 key购买 nike

我想使用 Spotify iOS SDK 从选定的播放列表中获取轨道。但它总是不返回我的数组中的任何项目。我正在使用以下代码来获取轨道:

[SPTPlaylistSnapshot playlistWithURI:selectedPlaylist.uri accessToken:auth.session.accessToken callback:^(NSError *error, id object) {

if (!error) {
SPTPlaylistSnapshot *playlistSnapchot = object;

NSArray *songItemsArray = playlistSnapchot.firstTrackPage.items;
NSLog(@"LOADED: %@", songItemsArray);

[songItemsArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

SPTPartialTrack *track = obj;
NSLog(@"%@", track.name);


}];

}
else
{
NSLog(@"Error loading Playlist Tracks: %@", error.localizedDescription);
}

}];

每次我的songsItemsArray 都是(null)

有谁知道这个问题的原因是什么?我正在使用所有 Spotify 范围。

最佳答案

这可能是由于缺少链接器标志,将“-all_load”添加到项目中的其他链接器标志。

我在我的应用程序中这样做,这是我的代码:

func getTracksFrom(page:SPTListPage, allItems:[SPTPlaylistTrack]) -> [SPTPlaylistTrack] {
guard let items = page.items as? [SPTPlaylistTrack] else {print("empty page");return allItems}
var allTracks = allItems
allTracks.append(contentsOf: items)

var nextPage = SPTListPage()

if page.hasNextPage {
page.requestNextPage(withAccessToken: (SPTAuth.defaultInstance().session.accessToken)!) { (error, data) in
guard let p = data as? SPTListPage else {return}
nextPage = p
}

return getTracksFrom(page:nextPage,allItems:allTracks)
}
return allTracks
}

func getAllTracksFrom(_ playlist:SPTPlaylistSnapshot) -> [SPTPlaylistTrack] {
var allTracks:[SPTPlaylistTrack] = []
allTracks = getTracksFrom(page: playlist.firstTrackPage, allItems: allTracks)
return allTracks
}

override func viewDidLoad() {
super.viewDidLoad()
guard let p = playlist else {return}
SPTPlaylistSnapshot.playlist(withURI: p.uri, accessToken: (SPTAuth.defaultInstance().session.accessToken)!, callback: { (error, dataOrNil) in
guard error == nil else {print(error!);return}
guard let playlistSnapshot = dataOrNil as? SPTPlaylistSnapshot else {print("couldn't cast as SPTPlaylistSnapshot");return}
self.tracks = self.getAllTracksFrom(playlistSnapshot)
self.tableView.reloadData()
})
}

关于ios - Spotify iOS-SDK : Get Tracks from Playlist returns (null) Tracks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39942669/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com