How to retrieve user's saved tracks in Spotify iOS SDK?

I’m working with the Spotify iOS SDK beta 6 and I’m stuck trying to get a list of my saved tracks. There’s a method called getSavedTracks that I want to use, but I’m not sure how to implement it correctly.

Here’s what I’ve tried so far:

// Method call
[self getSavedTracks:(SPTSavedTrack *__autoreleasing *) range:(NSRange)]

// Method implementation
-(void)getSavedTracks:(SPTSavedTrack **)buffer range:(NSRange)inRange {
    [SPTRequest savedTracksForUserInSession:self.session callback:^(NSError *error, SPTSavedTrack *trackObjects) {
        if (error != nil) {
            NSLog(@"Error fetching saved tracks: %@", error);
            return;
        }
        self.savedTracks = [NSMutableArray arrayWithObject:trackObjects];
    }];
}

I’m not confident about the parameters I should use or if this implementation is correct. The SDK docs don’t mention this method specifically. Any help or guidance would be great! How can I properly fetch and store the user’s saved tracks using this SDK?

As someone who’s dealt with the Spotify iOS SDK extensively, I can offer a different perspective. While the SPTRequest method suggested is valid, I’ve found that using the newer SPTTrackProvider class can be more efficient and easier to maintain in the long run.

Here’s a code snippet that’s worked well in my projects:

SPTTrackProvider *trackProvider = [SPTTrackProvider savedTracksForUser:self.session.canonicalUsername
                                                             inSession:self.session];
[trackProvider loadTracksAtOffset:0 withCount:50 callback:^(NSError *error, NSArray *tracks) {
    if (error) {
        NSLog(@"Error loading saved tracks: %@", error);
        return;
    }
    // Process the tracks array
}];

This approach handles pagination more gracefully and allows for better control over the number of tracks fetched at once. It’s also more in line with Spotify’s recent API changes. Remember to implement proper error handling and consider caching results for improved performance.

yo, have u tried using SPTTrackProvider? it’s pretty cool for getting saved tracks. just create a provider with ur session, then use loadTracksAtOffset:withCount:callback: to fetch em. way easier than messing with SPTRequest imo. give it a shot!

hey man, i had similar issues. try using SPTRequest requestUserSavedTracksForUsername:session:callback: instead. it’s more straightforward. just pass ur session and handle the response in the callback. might need to adjust ur code a bit but should work. good luck!

I’ve been tinkering with the Spotify iOS SDK recently, and I found a method that works pretty well for fetching saved tracks. Instead of using getSavedTracks or SPTRequest, try the SPTAppRemote class. It’s part of the newer SDK versions and offers a more streamlined approach.

Here’s a snippet that’s been reliable for me:

[self.appRemote.userAPI fetchSavedTracksForCurrentUserWithCallback:^(id _Nullable result, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Error fetching saved tracks: %@", error);
        return;
    }
    
    NSArray<SPTAppRemoteTrack *> *tracks = result;
    // Process the tracks array
}];

This method handles pagination automatically and gives you direct access to SPTAppRemoteTrack objects. It’s been more stable in my experience, especially when dealing with larger libraries. Just make sure you’ve properly set up SPTAppRemote with your client ID and redirect URI. Hope this helps!

I’ve been working with the Spotify iOS SDK for a while now, and I can share some insights on retrieving saved tracks. The getSavedTracks method you’re trying to use isn’t the most reliable approach in my experience. Instead, I’d recommend using the SPTRequest class with the requestUserSavedTracksForUsername:session:callback: method.

Here’s a snippet that’s worked well for me:

[SPTRequest requestUserSavedTracksForUsername:self.session.canonicalUsername
                                      session:self.session
                                     callback:^(NSError *error, id object) {
    if (error) {
        NSLog(@"Error fetching saved tracks: %@", error);
        return;
    }
    
    SPTListPage *listPage = (SPTListPage *)object;
    NSArray *savedTracks = listPage.items;
    
    // Do something with savedTracks
}];

This approach has been more consistent and easier to work with. Remember to handle pagination if you’re dealing with a large number of saved tracks. Hope this helps!