Using UIActivityViewController to specify file type
Asked Answered
S

1

1

Following up from this question, how would I go about using UIActivityViewController to specify the file type of a file I am sharing over airdrop?

Sucker answered 17/7, 2017 at 23:39 Comment(0)
S
-1

Worked it out:

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)
Sucker answered 18/7, 2017 at 2:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.