从iOS导出到Google云端硬盘

时间:2018-06-01 16:17:27

标签: ios swift google-drive-api

我正在尝试使用Swift中的UIActivityViewController将一段文本导出到Google云端硬盘。导出有效,但文件最终以“错误”格式出现在Google云端硬盘中。它可以打开然后转换为Google文档,但理想情况下,我希望用户不必再执行这一额外步骤。我的代码如下:

     @IBAction func shareFinalProduct(_ sender: UIButton) {
    let fileName = "ExportedFile.doc"
    let path = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(fileName)
    if let product = finalProductText.text {

        do {
            try product.write(to: path!, atomically: true, encoding: String.Encoding.utf8)
        } catch {
            print("Failed to create file")
            print("\(error)")
        }
        let vc = UIActivityViewController(activityItems: [path!], applicationActivities: nil)
        vc.title = "Sharing"
        vc.excludedActivityTypes = []
        vc.popoverPresentationController?.sourceView = self.view
        vc.popoverPresentationController?.sourceRect = sender.frame
        present(vc, animated: true, completion: nil)
    }
}

我尝试将文件名的扩展名更改为“.txt,.docx,.rtf”,但导入后仍需将文件转换为Google Doc格式。我是否需要创建自定义UIActivity?

0 个答案:

没有答案