如何在存储在本地目录中的iOS中编辑和保存Microsoft Word文档?

时间:2017-09-16 06:51:35

标签: ios swift swift3 dropbox

我正在使用Dropbox和Microsoft Word。我可以从Dropbox下载文件并存储在本地存储(在Document目录中)。现在我要编辑word文档。我尝试了几种方式,但它不适合我。

下载到本地存储中并使用UIDocumentInteractionController使用Microsoft Word打开,但它打开只读副本并保存在Microsoft Word应用程序中:

let file = URL(fileURLWithPath: dirPath).appendingPathComponent("/\(filename)")
// Do whatever you want with the document
self.docController = UIDocumentInteractionController(url: file)
self.docController.delegate = self
self.docController.presentOpenInMenu(from: self.view.frame, in: self.view, animated: true)

使用Microsoft word app的URL方案在本地存储中下载并使用Microsoft Word打开但是失败并显示错误无法打开文件:

let url : NSString = "ms-word:ofe|u|\(directoryContents[0])|z|yes|a|App" as NSString
let urlStr : NSString = url.addingPercentEscapes(using: String.Encoding.utf8.rawValue)! as NSString
let searchURL : NSURL = NSURL(string: urlStr as String)!
UIApplication.shared.openURL(searchURL as URL)

enter image description here

使用Microsoft Word应用程序的URL方案直接在word应用程序中下载文件(使用Dropbox共享链接),但它失败并显示错误无法打开文件:

let url : NSString = "ms-word:ofv|u|https://www.dropbox.com/s/xxxxxx/new.docx?dl=0|p|xxxxxx|z|yes|a|App" as NSString
let urlStr : NSString = url.addingPercentEscapes(using: String.Encoding.utf8.rawValue)! as NSString
let searchURL : NSURL = NSURL(string: urlStr as String)!
UIApplication.shared.openURL(searchURL as URL) 

enter image description here enter image description here

我知道这是因为iOS Sandboxing。不允许在整个应用中共享数据。我不想使用Dropbox应用编辑文件并进行更新吗?

有没有办法从Dropbox下载word文件并在应用内编辑或使用Microsoft Word应用程序?

0 个答案:

没有答案