iosswiftsdkdeezer

Deezer SDK IOS play track by id


The official examples of Deezer's API in swift show us a method called getObject in the DeezerManager.

func getObject(identifier: String, callback: @escaping (_ object: Any?, _ error: Error?) -> Void) {
    DZRObject.object(withIdentifier: identifier, requestManager: DZRRequestManager.default(), callback: callback)
}

I want to play a track with id 533609232 (Drake - God's Plan). To do it, I need to have the DZRTrack/DZRObject. So I called:

DZRObject.object(withIdentifier: "533609232", requestManager: DZRRequestManager.default(), callback: { (data, error) in
    print(data, error)
    //player stuff
})

But I've got an error NSException:

2019-05-02 22:50:23.845973+0200 my-app[51762:1318493] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010af7d6fb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x0000000109dd2ac5 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010aecbddc _CFThrowFormattedException + 194
    3   CoreFoundation                      0x000000010af5786d -[__NSPlaceholderArray initWithObjects:count:] + 237
    4   CoreFoundation                      0x000000010af6c2a4 +[NSArray arrayWithObjects:count:] + 52
    5   my-app                              0x0000000106af3ef5 +[DZRObject infoURLWithBaseURL:identifier:] + 134
    6   my-app                              0x0000000106af4062 +[DZRObject objectWithRequestManager:baseURL:identifier:callback:] + 123
    7   my-app                              0x0000000106af3fb3 +[DZRObject objectWithIdentifier:requestManager:callback:] + 80
    8   my-app                              0x00000001069cd93d $s10my_app30DeezerViewControllerC5testayyF + 461
    9   my-app                              0x00000001069cf75e $s10my_app30DeezerViewControllerC0C6ActionyyF + 46
    10  my-app                              0x00000001069cf794 $s10my_app30DeezerViewControllerC0C6ActionyyFTo + 36
    11  UIKitCore                           0x000000010fd73204 -[UIApplication sendAction:to:from:forEvent:] + 83
    12  UIKitCore                           0x000000010f7c8c19 -[UIControl sendAction:to:forEvent:] + 67
    13  UIKitCore                           0x000000010f7c8f36 -[UIControl _sendActionsForEvents:withEvent:] + 450
    14  UIKitCore                           0x000000010f7c7eec -[UIControl touchesEnded:withEvent:] + 583
    15  UIKitCore                           0x000000010fdabeee -[UIWindow _sendTouchesForEvent:] + 2547
    16  UIKitCore                           0x000000010fdad5d2 -[UIWindow sendEvent:] + 4079
    17  UIKitCore                           0x000000010fd8bd16 -[UIApplication sendEvent:] + 356
    18  UIKitCore                           0x000000010fe5c293 __dispatchPreprocessedEventFromEventQueue + 3232
    19  UIKitCore                           0x000000010fe5ebb9 __handleEventQueueInternal + 5911
    20  CoreFoundation                      0x000000010aee4be1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    21  CoreFoundation                      0x000000010aee4463 __CFRunLoopDoSources0 + 243
    22  CoreFoundation                      0x000000010aedeb1f __CFRunLoopRun + 1231
    23  CoreFoundation                      0x000000010aede302 CFRunLoopRunSpecific + 626
    24  GraphicsServices                    0x00000001136072fe GSEventRunModal + 65
    25  UIKitCore                           0x000000010fd71ba2 UIApplicationMain + 140
    26  my-app                              0x00000001068d4ebb main + 75
    27  libdyld.dylib                       0x000000010cfc9541 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

So I don't understand why I got this error. Am I doing wrong? Is it an other way to do it?


Solution

  • As stated by the Deezer SDK documentation (DZRObject.h)

    You should not call this method directly on the DZRObject class but on one of its concrete subclass (e.g. DZRUser, DZRTrack, DZRArtist, ...)

    Maybe try DZRTrack.object(withIdentifier... instead?