ActivityViewController按预期工作,但如果我将URL作为activityItem传递,则会导致内存泄漏。除了导出之外,不需要此文件(archivedFile)。
let fileName = "test.myuti"
let tempDirURL: URL = FileManager.default.temporaryDirectory
let fullWriteURL: URL = tempDirURL.appendingPathComponent(fileName)
let exportCode = ExportCode(mainObject: theExpObject, mainObTitle: theTitle)
let dicToArchive = exportCode.createFileToExport()
let archivedFile = NSKeyedArchiver.archivedData(withRootObject: dicToArchive)
do {
try archivedFile.write(to: fullWriteURL, options: [.atomic])
}
catch {
errAlrt("Could not create an export file")
}
let activityVC = UIActivityViewController(activityItems: [fullWriteURL], applicationActivities: nil)
activityVC.excludedActivityTypes = [.assignToContact, .postToFacebook, .postToTwitter, .addToReadingList, UIActivityType(rawValue: "com.apple.mobilenotes.SharingExtension"), UIActivityType(rawValue: "com.apple.reminders.RemindersEditorExtension"), .postToFlickr, .postToWeibo, .saveToCameraRoll, .copyToPasteboard, .openInIBooks, .print, .postToTencentWeibo]
let popCntrl = activityVC.popoverPresentationController
popCntrl?.permittedArrowDirections = .any
popCntrl?.sourceView = self.view
popCntrl?.sourceRect = CGRect(origin: CGPoint(x: 0,y :0), size: CGSize(width: 200, height: 200))
self.present(activityVC, animated: false, completion: nil)