Yuuu
Yuuu

Reputation: 879

In which situation adding a new video asset to the Photos library fails?

I'm working on an iOS app that allows users to save the captured video on their iOS devices. After some research, now I'm able to save the video on the device, but I was wondering what kind of situation the app fail to save the video. In the completion block of performChages, it takes two parameters, saved and error in the code below. Since the first parameter is a type of Bool, I think there are some cases when fails to save the video on the device. But it also has an error, so I was wondering what situation could return an error.

success

true if Photos successfully applied the changes requested in the block; otherwise, false.

error

If an error occurs, an NSError object describing the error; otherwise, nil.

Another question is how can I handle when I get success = false in the completion handler. Is it possible to try save the video once more when I get success as false?

guard let writer: AVAssetWriter = recorder.writer else { return }
PHPhotoLibrary.shared().performChanges({() -> Void in
    PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: writer.outputURL)
}, completionHandler: {saved, error -> Void in
    if let error = error {
        print("error: \(error)")
    } else if saved {
        print("saved")
    } else {
        print("failed")
    }
})

Upvotes: 0

Views: 27

Answers (0)

Related Questions