Dropbox API in iOS: How to use DBRestClient?

你。 提交于 2020-01-14 06:07:07

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/10248034/dropbox-api-in-ios-how-to-use-dbrestclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!