本文介绍了使用 UIActivityViewController 指定文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

解决了:

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)

这篇关于使用 UIActivityViewController 指定文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:14