iosobjective-cdropbox

Dropbox API in iOS: How to use DBRestClient?


I'm trying to follow the instructions on the Dropbox developer's site, but I can't figure out how to properly add a DBRestClient object. Right now in my .h file after @end I have:

DBRestClient *restClient;

And in my .m file I have:

- (DBRestClient *)restClient {
    if (!restClient) {
        restClient =
        [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
        restClient.delegate = self;
    }
    return restClient;
}

This is what the Dropbox page tells me to do, I think; however this results in my app crashing (I think because it tries to release restClient when it shouldn't). I've also tried listing restClient as a nonatomic property but then the uploading, etc methods don't seem to work. (The upload method IS working right now, the app just crashes once it's finished uploading...) Help?


Solution

  • Rupesh, the detailed canonical answer based on bee's comment on Apr 20 is that self was getting deallocated.

    this means there must have been code that did the following in order.

    1. a variable created by calling the restClient function that returns an object of type (DBRestClient*)
    2. that variable sets it's component (@property? probably) delegate to self in that function (seen in the question above)
    3. later, the object self was pointing to was deallocated, meaning delegate was not pointing to anything.
    4. later still, there must have been code that was attempting to dereference delegate for some purpose.

    do remember that sending messages to nil objc objects only effectively results in nothing happening or a zero assignment if the message being sent is a function. thus a crash must have been due to some other kind of dereference.