在UIActivityViewController中共享URL显示内存泄漏

时间:2016-11-12 20:32:38

标签: ios swift memory-leaks uipopovercontroller uiactivityviewcontroller

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)

memory leak

0 个答案:

没有答案