Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can access the documents from DropBox in my ios application

I am trying to implement an IOS application. The need of my application is to access the documents(pdf,photo etc) from DropBox Application(My iphone has DropBox Application ) .I am new in iphone development ,so i have no idea about access the document from DropBox.

If anybody know please help me . Thanks in advance.

like image 980
John Avatar asked Feb 22 '23 10:02

John


1 Answers

First, you will need official Dropbox iOS SDK. Next, you will need an application key, which you can obtain from Dropbox website (choose MyApps). You will notice that the Dropbox iOS SDK comes with a bundled demo application, so have a look there. Also, good starting tutorial can be found here.
To access a file, your code will look something like:

 NSString* consumerKey; //fill your key
 NSString* consumerSecret ; //fill your secret
 DBSession* session = [[DBSession alloc] initWithConsumerKey:consumerKey 
       consumerSecret:consumerSecret];
 session.delegate = self;
 [DBSession setSharedSession:session];
 [session release];
 if (![[DBSession sharedSession] isLinked])
 {
        DBLoginController* controller = [[DBLoginController new] autorelease];
        controller.delegate = self;
        [controller presentFromController:self];
 }
 DBRestClient *rc = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
 self.restClient = rc;
 [rc release];
 self.restClient.delegate = self;

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0];
 NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"SampleFile.txt"];
 [self.restClient loadFile:@"/example/SampleFile.txt" intoPath:filePath];

Please note that iOS Dropbox SDK requires iOS 4.2 or greater.

like image 138
Maggie Avatar answered Mar 23 '23 00:03

Maggie