Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在ios应用程序中从DropBox访问文档_Iphone_Ios4_Dropbox - Fatal编程技术网

Iphone 如何在ios应用程序中从DropBox访问文档

Iphone 如何在ios应用程序中从DropBox访问文档,iphone,ios4,dropbox,Iphone,Ios4,Dropbox,我正在尝试实现一个IOS应用程序。我的应用程序需要从DropBox应用程序(我的iphone有DropBox应用程序)访问文档(pdf、照片等)。我是iphone开发新手,所以我不知道如何从DropBox访问文档 如果有人知道,请帮助我。提前谢谢 首先,您需要正式的Dropbox iOS SDK。接下来,您需要一个应用程序密钥,您可以从Dropbox网站(选择MyApps)获取该密钥。您会注意到Dropbox iOS SDK附带了一个捆绑的演示应用程序,请看这里。此外,还可以找到良好的入门教程。

我正在尝试实现一个IOS应用程序。我的应用程序需要从DropBox应用程序(我的iphone有DropBox应用程序)访问文档(pdf、照片等)。我是iphone开发新手,所以我不知道如何从DropBox访问文档


如果有人知道,请帮助我。提前谢谢

首先,您需要正式的Dropbox iOS SDK。接下来,您需要一个应用程序密钥,您可以从Dropbox网站(选择MyApps)获取该密钥。您会注意到Dropbox iOS SDK附带了一个捆绑的演示应用程序,请看这里。此外,还可以找到良好的入门教程。
要访问文件,您的代码如下所示:

 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或更高版本。

您可以使用类从共享其文件的其他应用程序访问文件。你可以找到所有的

您将看到这种选择文档的屏幕


您无法访问其他应用程序的文档。您应该使用Dropbox API
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)")
  }
}