我正在尝试实施IOS应用程序。我的应用程序的需要是从DropBox应用程序(我的iphone有DropBox应用程序)访问文档(pdf,照片等)。我是iphone开发的新手,所以我不知道从DropBox访问文档。
如果有人知道请帮助我。提前致谢。
答案 0 :(得分:8)
首先,您需要官方的Dropbox iOS SDK。接下来,您将需要一个应用程序密钥,您可以从Dropbox网站获取该应用程序密钥(选择MyApps)。您会注意到Dropbox iOS SDK附带了一个捆绑的演示应用程序,所以看看那里。此外,可以找到良好的入门教程here 要访问文件,您的代码将类似于:
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];
请注意,iOS Dropbox SDK需要iOS 4.2或更高版本。
答案 1 :(得分:0)
您可以使用UIDocumentMenuViewController
类来访问共享其文件的其他应用程序中的文件。您可以找到所有UTI
's 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)")
}
}
您将看到这种用于选择文档的屏幕