Using loadDelta feature in Dropbox IOS - ios

I am using dropbox to upload and download files. I want to be able to be notified when a file changes in a certain folder (or if not possible in the entire dropbox account) so that the user is advised. I don't seem to find any way to do it apart from using the delta feature. I found this code:
-(void)restClient:(DBRestClient *)client loadedDeltaEntries:(NSArray *)entries reset:(BOOL)shouldReset cursor:(NSString *)cursor hasMore:(BOOL)hasMore{
for (DBDeltaEntry *file in entries) {
if(!file.metadata.isDirectory){
NSLog(#"File: %# ", file.metadata.filename );
}else {
NSLog(#"Directory: %# ", file.metadata.filename );
}
}
}
....from this stack overflow question: Using Delta in Dropbox API with iOS
But it gives errors. I found out there is a feature like:
[self.restClient loadDelta:NSString];
But I don't seem to find any examples, and please don't give me a link to the dropbox site which has no sample code at all.

Related

Dropbox v2 api for iOS - how do you get clientMTime?

I'm migrating an app built with the Dropbox v1 API to the v2 API. The app needs to sync files in source dropbox folder to app documents folder. The current version of the app uses the clientMTime to skip syncing files which have not changed. With v1, I got the required info--specifically the path and clientMTime of each file in the Dropbox folder--by doing this...
// ==============================================================
// getDBMetadata
// ==============================================================
- (void)getDBMetadata
{
NSString* theOPMLFilesRoot = #"/";
[self.restClient loadMetadata:theOPMLFilesRoot withHash:self.opmlFilesHash];
}
// ==============================================================
// restClient:loadedMetadata:
// ==============================================================
- (void)restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata
{
self.opmlFilesHash = metadata.hash; // Used to check for changes
for (DBMetadata* __unused theMetadata in metadata.contents) {
LogDebug(#"Path: %#, clientMtime: %#.", theMetadata.path , [theMetadata.clientMtime toStr]);
}
[self synchronizeFilesUsingDBMetadata:metadata];
}
The v2 iOS API docs for Dropbox object 'DBFILESMetadata' include 'path' but do not list clientMtime as an included property (which they're calling 'field'). Is there a way to get clientMTime with v2?
The DBFILESMetadata can represent a file, folder, or deleted item. Only files have a client modified time though, so clientModified is only available on DBFILESFileMetadata, which represents a file only.
DBFILESFileMetadata is a subclass of DBFILESMetadata. To check if a particular DBFILESMetadata is a DBFILESFileMetadata, you can use isKindOfClass as shown here. You can then cast it to the relevant subclass.
Also, note that rev or contentHash are better options for checking if the file has changed.

Dropbox SDK Chooser download file

I would like to download a file from dropbox into my app i already implemented the Dropbox Drop-in API chooser so i get directed to the dropbox app and can choose a file but i don't know how to download the selected file
- (void)didPressChoose{
[[DBChooser defaultChooser] openChooserForLinkType:DBChooserLinkTypePreview
fromViewController:self completion:^(NSArray *results)
{
if ([results count]) {
fileurl = [[results[0] link] absoluteString];
NSLog(#"got results %#", results);
NSLog(#"link 0 = %#", [[results[0] link] absoluteString]);
} else {
// User canceled the action
}
}];
}
I tried this but i only get a link like "dropbox.com/s/2hro2i45h ..." but for this
[self.restClient loadFile:fileurl intoPath:localDir];
I need something like "/test.txt"
First, the documentation for the Dropbox iOS Chooser lists two different link types. If you want to download the file directly, you should use DBChooserLinkTypeDirect instead of DBChooserLinkTypePreview as you have in your code.
Second, once you have the direct link, you can use a normal HTTP request on the link to download the file content, e.g., using NSURLRequest. The loadFile method you have in your code is for the Dropbox iOS Core SDK which you don't need to use if you're just using the Chooser. That method won't work with the link returned by the Chooser anyway. That method is designed to take a relative path in a user's Dropbox account, but the Chooser is a simpler integration that just gives you a link instead.
I'm not sure but I have this before calling loadFile on restClient
NSString* filePath = [path stringByReplacingOccurrencesOfString:#"dropbox://" withString:#""];
[restClient loadFile:filePath intoPath:destinationPath];

Dropbox Core API, notification if a file has been added to a folder

I have an app that creates tickets by putting a file in a Dropbox folder. Based on this ticket a file is added to another (Dropbox) folder. I use the Dropbox Core API.
Now, I have to refresh the folder manually to see if the new file already has been added.
I am searching for a method to be notified when the folder is changed (a file has been added) but haven't found it. I guess longpoll_delta can do the job but that isn't available in the iOS API.
Is there a method to do this in Objective-c?
I retrieve the data the following way:
- (void) refreshTable {
[self.restClient loadMetadata:#"path"];
}
- (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata {
for (DBMetadata * child in metadata.contents) {
if (!child.isDirectory && !child.isDeleted) {
NSLog(#"Filename: %#", child.filename);
}
}
}
Any ideas?
The new Dropbox API v2 has function for this:
[[[dropboxClient.filesRoutes listFolderLongpoll:cursor] setResponseBlock:...];
Cursor parameter is returned by listFolder or listFolderContinue.

Preview of dropbox file in iOS

I am integrating dropbox with my IOS application. I am able to fetch selected file meta data. But couldn't find the way to show preview after selecting the file. Can someone suggest which API is helpful.
Drop box i am using is : https://www.dropbox.com/developers/dropins/chooser/ios
Below piece of code is called when user wants to select file from dropbox :
- (void)didPressChoose
{
[[DBChooser defaultChooser] openChooserForLinkType:DBChooserLinkTypePreview fromViewController:self
completion:^(NSArray *results)
{
if ([results count]) {
_result = results[0];
//After getting the result, i want to preview the file
} else {
_result = nil;
[[[UIAlertView alloc] initWithTitle:#"CANCELLED" message:#"user cancelled!"
delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil]
show];
}
[[self tableView] reloadData];
}];
}
When you ask for DBChooserLinkTypePreview, the DBChooserResult you get back from the Chooser will have an NSURL link like this:
https://www.dropbox.com/s/toyzur6e0m34t7v/dropbox-logos_dropbox-glyph-blue.png
This link type is meant for direct user interaction, so you can send a user there and Dropbox will display the page with a preview of the file if possible.
Alternatively, you may want to use DBChooserLinkTypeDirect which gives you a direct link like this:
https://dl.dropboxusercontent.com/1/view/969vkzdys770277/Testing/Images/dropbox-logos_dropbox-glyph-blue.png
This is a direct (but temporary) link to the file contents. You can download the file contents programmatically (e.g., see How do I download and save a file locally on iOS using objective C? ) and then do whatever you want with it. For example, you may want to display it in an UIImageView if it's an image, etc.
Also, DBChooserResult contains a thumbnails property with links to thumbnails (if the selected file was an image or video) that might be similarly useful.

How to display Dropbox Folders after logging in

I am in the process of learning the Dropbox SDK. I want to learn how to display the users Dropbox folders as well as give the user the option to upload the file from my app to their Dropbox account.
I have looked through their example app but it is not giving me the info that I need.
Can someone help me with this please?
I think you might find this tutorial useful.
http://www.nanaimostudio.com/blog/2011/1/20/how-to-synchronize-your-app-data-using-dropbox-api.html
You can call upload method on the DBRestClient object.
NSString* path = [self getDocumentPath];//or however you can obtain the path where your file is stored
[restClientObject uploadFile:#"filename" toPath:#"/" fromPath:path];
//you can choose to upload to the dropbox root directory(above) or a folder of your choice eg toPath:#"/myfolder"
Use loadMetaData for displaying the contents of dropbox folder
[restClientObject loadMetadata:#""];
you also have to implement loadedMetadatafunction. Refer the tutorial above.
-(void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata{
NSMutableArray *list=[[NSMutableArray alloc] init];
for (DBMetadata *child in metadata.contents) {
[list addObject:child];
}
self.arrayFoldersList=[[NSMutableArray alloc] initWithArray:list];
[self.tableView reloadData];
}
[self.restClient loadMetadata:#""];
I think this will help you alot.

Resources