我有一个Swift 4.2脚本,可以使用MFMessageCompose发送附件视频。我注意到每次发送视频时,内存使用量都会增加。当我退出MessageView时,内存不会释放。每次我使用MFMessageController发送附件时,内存都会增加。我运行了调试程序,它通知我IOSurface中的内存泄漏。我按下按钮时会打开带有附件的MFMessage视图。即使我取消了它,内存也会显示增加。当我按下此按钮时,内存只会跳到附件的大小。下面提供了我正在使用的代码。有人可以帮我弄清楚如何释放此内存,以便我的应用在多次发送后不会崩溃吗?
//从UIViewController上的按钮开始发送操作 @IBAction func sendMessage(_ sender:Any){
func sendSMS(attachment: String) {
}
}
if let vid = self.selectedVideo {
self.titleLabel.text = vid.videoTitle
self.descriptionLabel.text = vid.videoDescription
let requestObj2 = (vid.videoId + ".mp4")
sendSMS(attachment: requestObj2)
// Check if the device is capable of sending text message
guard MFMessageComposeViewController.canSendText() else {
let alertMessage = UIAlertController(title: "SMS unavailable", message: "Your device is not capable of sending SMS.", preferredStyle: .alert)
alertMessage.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
present(alertMessage, animated: true, completion: nil)
return
}
// Prefill the SMS
let messageController = MFMessageComposeViewController()
messageController.messageComposeDelegate = self
messageController.recipients = [" "]
messageController.body = " "
print("prefill the SMS")
//Adding file attachment
let fileparts = requestObj2.components(separatedBy: ".")
let filename = fileparts[0]
let fileExtension = fileparts[1]
let filePath = Bundle.main.path(forResource: filename, ofType: fileExtension)
let fileUrl = NSURL.fileURL(withPath: filePath!)
messageController.addAttachmentURL(fileUrl, withAlternateFilename: nil)
//Present message view controller on screen
present(messageController, animated: true, completion: nil)
print("present message view")
return