0

I am trying to obtain the cover artwork image with Spotify iOS SDK. As I understand the API, there are convenience methods of the SPTArtist object for the smallest and largest SPTImage. When the audioStreaming controller delegate fires at the start of a new track, it provides track metadata for the current song that includes the SPTAudioStreamingMetadataArtistURI. I am trying to use this URI to obtain the SPTArtist object for this song in the following way:

-(void)audioStreaming:(SPTAudioStreamingController *)audioStreaming didChangeToTrack:(NSDictionary *)trackMetadata {
    [SPTArtist artistWithURI:trackMetadata[SPTAudioStreamingMetadataArtistURI] session:[SpotifySettingsHelper session] callback:^(NSError *error, id object) {
        ...
        // asynchronously obtain the image
        NSData *imageData = [NSData dataWithContentsOfURL:artist.largestImage.imageURL options:0 error:&error];
        ...
    }];
}

The [SPTArtist artistWithURI:session:callback] call is crashing with the following error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString absoluteString]: unrecognized selector sent to instance 0x7f9ed0ebe4d0'
*** First throw call stack:
(
0   CoreFoundation                      0x000000010d43ff35 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010d0d8bb7 objc_exception_throw + 45
2   CoreFoundation                      0x000000010d44704d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x000000010d39f27c ___forwarding___ + 988
4   CoreFoundation                      0x000000010d39ee18 _CF_forwarding_prep_0 + 120
5   MyGreatApp                        0x000000010a08a053 __52+[SPTRequest requestItemAtURI:withSession:callback:]_block_invoke + 160
6   libdispatch.dylib                   0x000000010d919ba6 _dispatch_call_block_and_release + 12
7   libdispatch.dylib                   0x000000010d9377f4 _dispatch_client_callout + 8
8   libdispatch.dylib                   0x000000010d92215d _dispatch_root_queue_drain + 1097
9   libdispatch.dylib                   0x000000010d9235d9 _dispatch_worker_thread3 + 111
10  libsystem_pthread.dylib             0x000000010dcbb6cb _pthread_wqthread + 729
11  libsystem_pthread.dylib             0x000000010dcb94a1 start_wqthread + 13

)

What is wrong with this approach? If this is not the proper way, how should I be obtaining the artwork?

1 Answer 1

1

It looks like you're passing an NSString to an API that wants an NSURL. Check what trackMetadata[SPTAudioStreamingMetadataArtistURI] returns — if it's an NSString, use [NSURL urlWithString:] to convert it.

Also, in your code you write // asynchronously obtain the image then perform a synchronous task. That'll block your main thread for a large amount of time.

2
  • It contains a URI in the form of spotify:* (spotify:artist:70kkdajctXSbqSMJbQO424). This is what the API describes as the required input (see developer.spotify.com/ios-sdk-docs/Documents/Classes/…). With respect to you comment on the asynchronous task, I was lazy and did not put all the code in for that (just trying to give an idea of what I was going to do with the SPTArtist object once I received it). I tried your suggestion anyway. Doesn't crash, but return object is nil (and error is nil). Any other thoughts?
    – JeffB6688
    Jan 8, 2015 at 17:44
  • Oops. xcode was showing the object as being nil, but then I printed the object with po object. It did work. I guess I was being too literal with the API comments. Your suggestion worked. Thanks.
    – JeffB6688
    Jan 8, 2015 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.