0

这个问题开始,我将如何使用UIActivityViewController来指定我通过空投共享的文件的文件类型?

4

1 回答 1

0

解决了:

let myFileManager = FileManager.default
    var activityArray = [NSURL]()
    activityArray.removeAll()

    for (i, data) in dataToShare.enumerated() {
        let docsurl = try! myFileManager.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
        let myurl = docsurl.appendingPathComponent("shareData\(i).gymProf")
        var myUrlString = myurl.absoluteString

        myUrlString = myUrlString.replacingOccurrences(of: "file://", with: "")
        myFileManager.createFile(atPath: myUrlString, contents: data, attributes: nil)
        activityArray.append(NSURL(fileURLWithPath: myUrlString))

        if myFileManager.fileExists(atPath: myUrlString) {
            print("File Exists at \(myUrlString)")
        } else {
            print("File not found")
        }

    }

    let activityViewController = UIActivityViewController(activityItems: activityArray, applicationActivities: nil)
    activityViewController.popoverPresentationController?.sourceView = self.view

    self.present(activityViewController, animated: true, completion: nil)
于 2017-07-18T02:19:14.723 回答