How to retrieve saved tracks using Spotify iOS SDK?

I’m working with the Spotify iOS SDK beta 6 and I’m stuck trying to get my saved tracks. The SDK has a getSavedTracks method, but I’m not sure how to use it correctly.

Here’s what I’ve tried:

[self getSavedTracks:(SPTSavedTrack *__autoreleasing *) range:(NSRange)];

// Implementation attempt
-(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 alloc] initWithObjects:trackObjects, nil];
    }];
}

I’m not confident about the parameters or the implementation. The SDK docs don’t mention this method. Any ideas on how to properly fetch saved tracks? Thanks for any help!

hey there! i ran into the same issue. the SDK’s a bit tricky. try using SPTTrackProvider instead of SPTSavedTrack. something like:

[SPTRequest savedTracksForUserInSession:session callback:^(NSError *error, id tracks) {
if (error) {
NSLog(@“oops: %@”, error);
return;
}
// use tracks here
}];

hope that helps!

I’ve been working with the Spotify iOS SDK recently, and I can share some insights on retrieving saved tracks. The getSavedTracks method you’re trying to use isn’t quite right. Instead, you should utilize the SPTRequest class with the savedTracksForUserInSession:callback: method.

Here’s a more appropriate approach:

[SPTRequest savedTracksForUserInSession:self.session callback:^(NSError *error, id<SPTTrackProvider> trackProvider) {
    if (error) {
        NSLog(@"Error fetching saved tracks: %@", error);
        return;
    }
    
    NSArray *tracks = [trackProvider tracks];
    // Process your tracks here
}];

This method returns an SPTTrackProvider object, which you can use to access the actual track objects. Remember to handle pagination if you have a large number of saved tracks. The SDK documentation should provide more details on working with SPTTrackProvider and pagination.