You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
Ghulam A.
9 years agoNew member | Level 1
Is linking necessary to download files?
Is it possible to download files from my app folder (Dropbox) to my app without linking an account? If so, how would I do that?
- Ghulam A.New member | Level 1
Basically, when I try to output the words in my text file, all I get back is null as so in my NSLog:
2016-01-08 22:38:45.124 My App Name[804:200098] (null)
Versus:
2016-01-08 22:42:30.358 DBRoulette[812:201530] Testing...
I know that the code I used works, because I tested it in DBRoulette logging in normally rather than using a token. I basically put the code inside the "Random photo" button's function and it worked fine. I got exactly what was in my text file to display in the NSLog as shown above.
- Greg-DBDropbox Staff
Have you implemented both of the delegate methods?
- (void)restClient:(DBRestClient*)client loadedFile:(NSString*)destPath;
- (void)restClient:(DBRestClient*)client loadFileFailedWithError:(NSError*)error;
What do you get from those?
- Ghulam A.New member | Level 1
On a side note, I've noticed that the file seems to remain cached (in DBRoulette) as when the function is called before linking it still displays text but the old text. I've tested this by changing the text in my text file between builds. Is this supposed to happen? Will all my files automatically cache for the user too? This is good if so, but I just wanted to make sure.
Anyways, I just tried implementing both delegate methods and added NSLogs inside them. In DBRoulette, which I know is working I did see the message I put in the loadFile: function so I confirmed again that it works there.
However, in my actual app I got nothing at all (not counting the previous (null) NSLog for displaying the contents of the file). Not even the NSLog error message in loadFileFailedWithError:. I don't think it would fail to load without an error so maybe it isn't loading at all? I have to be missing something, but I'm not quite sure what. Again, it has to be something with how I'm linking my account manually, because when I login to link it works perfectly fine with all the rest of the code being the same but not hen I use a token. You have my code above, but the only difference other than linking I can point out is that in the working one I put the download code in a function but in my actual app I put it in in the viewDidLoad
- Greg-DBDropbox Staff
The iOS Core SDK doesn't do any caching for you, and I'm not sure what functionality you're referring to in DBRoulette. The DBRoulette sample app displays images, not text, anyway, unless you're referring to a modified version of it?
Anyway, there are a few things that might cause your delegate methods to not be called:
1. Your rest client is nil or is being released (e.g., by ARC) prematurely.
2. You're making the call in a background thread that doesn't have a run loop.
3. Your delegate method that should be called back has a typo in it. Unfortunately the SDK doesn't warn you if it can't find a delegate method to call; it just completes without telling anyone. - Ghulam A.New member | Level 1
Yes, I was using a modified version. Do you see anything missing in the code for my app a few responses above? If not, where else should I check?
- Greg-DBDropbox Staff
Nothing jumps out at me, besides the lack of implementation of the delegate methods. Have you finished implementing those and looked into the causes I mentioned that may lead to them not being called?
- Ghulam A.New member | Level 1
Which delegate methods have I not implemented? I wasn't sure what was needed since I'm not going to have a normal login. Maybe that's what I'm missing.
- Greg-DBDropbox Staff
For loadFile, you just need these two:
- (void)restClient:(DBRestClient*)client loadedFile:(NSString*)destPath;
- (void)restClient:(DBRestClient*)client loadFileFailedWithError:(NSError*)error;
Earlier you did say you implemented them, but I wanted to check since that's the only thing that seemed to be missing from the latest code you've shared.
For loadMetadata you need:
- (void)restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata;
- (void)restClient:(DBRestClient*)client loadMetadataFailedWithError:(NSError*)error; - Greg-DBDropbox Staff
Two other things I just noticed:
- You don't seem to actually be constructing your client anywhere that you've shared. E.g.:
self.restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
self.restClient.delegate = self;- You're printing out the contents of the local file immediately after kicking off the API calls, but note that these calls are asynchronous, so you may be reading that data before the API call finished to download the latest version. That may be the "caching" you were referring to before.
- Ghulam A.New member | Level 1
Okay, that worked! I added those initialization lines to the viewDidLoad, but it still didn't work. I then moved the code for downloading the file and displaying it in an NSLog into a separate function outside of viewDidLoad and called it. That was what finally allowed it to work. Thanks so much for all your help!
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,880 PostsLatest Activity: 2 hours agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!