How to access documents from DropBox in ios app

I am trying to implement an iOS application. The need for my application is access to documents (pdf, photos, etc.) from the DropBox application (my iphone has a DropBox application). I'm new to iphone development, so I have no idea about accessing a document from DropBox.

If anyone knows, please help me. Thank you in advance.

+4
source share
2 answers

First you need the official Dropbox iOS SDK. Then you need the application key, which you can get on the Dropbox website (select MyApps). You'll notice that the Dropbox iOS SDK comes with the included demo app, so take a look there. In addition, a good basic tutorial can be found here .
To access the file, your code would look something like this:

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 higher.

+8
source

You can use the UIDocumentMenuViewController class to access files from other applications that share their files. You can find here the UTI here

 import MobileCoreServices class ViewController: UIViewController, UITextFieldDelegate, UIDocumentPickerDelegate, UIDocumentMenuDelegate { override func viewDidLoad() { super.viewDidLoad() } @IBAction func handleImportPickerPressed(sender: AnyObject) { let documentPicker = UIDocumentMenuViewController(documentTypes: [kUTTypePDF as String], in: .import) documentPicker.delegate = self present(documentPicker, animated: true, completion: nil) } // MARK:- UIDocumentMenuDelegate func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) { documentPicker.delegate = self present(documentPicker, animated: true, completion: nil) } // MARK:- UIDocumentPickerDelegate func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { // Do something print("\(url)") } } 

You will see a screen for selecting a document

dv0iQ.png

0
source

Source: https://habr.com/ru/post/1380718/


All Articles