Document Picker ios 8扩展,不从目录导入文件

时间:2016-02-04 09:58:40

标签: ios objective-c iphone xcode swift

我正在为我的应用使用文档选择器扩展程序。我使用了扩展名,即文档文件提供程序和文档提供程序来创建本地app目录。我的文件已成功保存在共享文件提供程序组中。当我尝试从谷歌驱动器,Dropbox或iCloud等第三方应用程序访问文件时,它就像一个魅力。但是当我尝试从我的应用程序目录中访问文档时,会将空文件复制到应用程序的临时目录中。我没有得到文件的内容。我的代码如下:

@IBAction func attachDocuments(sender: AnyObject) {

    let documentUTIs: NSArray = [ kUTTypePlainText as NSString , kUTTypePDF , kUTTypePNG , kUTTypeJPEG , kUTTypeText , kUTTypeContent ]
    let menuVC = UIDocumentMenuViewController(documentTypes: documentUTIs as! [String], inMode: UIDocumentPickerMode.Import)

    menuVC.delegate = self
    self.presentViewController(menuVC, animated: true, completion: nil)
    NSUserDefaults.standardUserDefaults().setBool(true, forKey: "fromCommentsView")
}

func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL) {

    let myData = NSData(contentsOfURL: url!)

        if myData != nil {
        self.uploadDocWebservice(url!, progressView: progressView, index: String(selectedDocNamesArray.count-1), imageData: myData, name: docName, mimeType: docExtension , uploadType: "Doc" )
        }else {

            let button = UIButton()
            button.tag = attachedDocArray.count + 1
            self.deleteDocAction(button)
            invokeAlertMethod("Error", msgBody: "File not supported", delegate: self)
        }

}

func documentMenuWasCancelled(documentMenu: UIDocumentMenuViewController) {

}

func documentMenu(documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
    documentPicker.delegate = self
    self.presentViewController(documentPicker, animated: true) { () -> Void in

    }
}

0 个答案:

没有答案