Как я могу получить URL-адрес последнего снятого мной видео? Я не хочу получать все видео, только последнее. Вот код, как я сохраняю видео, я создаю функцию сохранения, которая помогает мне сохранитьвидео в пользовательский альбом фотографий, а затем я вызываю эту функцию:
// Saving function
func saveVideo(vurl: URL) {
if assetCollection == nil {
return // If there was an error upstream, skip the save.
print("assetCollection = nil")
}
PHPhotoLibrary.shared().performChanges({
let assetChangeRequest = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: vurl)
let assetPlaceholder = assetChangeRequest!.placeholderForCreatedAsset
let albumChangeRequest = PHAssetCollectionChangeRequest(for: self.assetCollection)
albumChangeRequest!.addAssets([assetPlaceholder] as NSFastEnumeration)
print("TEST----------: \(albumChangeRequest!)")
}, completionHandler: nil)
}
// Saving proccess
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
print("Got a video")
if let pickedVideo:URL = info[UIImagePickerControllerMediaURL] as? URL {
// Save video to the custom photo album
print(pickedVideo)
if mainrepo == "" {
print("saving")
CustomPhotoAlbum.sharedInstance.saveVideo(vurl: pickedVideo)
// saving video url to core data
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let saver = NSEntityDescription.insertNewObject(forEntityName: "Repository", into: context)
let date = Date()
let formatter = DateFormatter()
formatter.dateFormat = "dd.MM.yyyy"
let calendar = Calendar.current
let hour = calendar.component(.hour, from: date)
let minutes = calendar.component(.minute, from: date)
let result = formatter.string(from: date)
print("time - \(hour):\(minutes)")
print("date - \(result)")
saver.setValue("\(pickedVideo)", forKey: "url")
saver.setValue("\(hour):\(minutes)", forKey: "time")
saver.setValue(result, forKey: "date")
saver.setValue("...", forKey: "comment")
appDelegate.saveContext()
print("saved")
}
}