To Camera Roll
VideoEditor SDK supports saving videos to the camera roll.
For the sake of this example, we create a video from a URL and present the video editor in a modal.
Note, that we have to make the current class the delegate of the
VideoEditViewController in order to handle export and cancellation there.
Implementing the Video Export Delegate Method#
When a video export is successful the method
videoEditViewControllerDidFinish is invoked on the delegate class and a
VideoEditorResult object is passed as an argument.
If no modifications have been made to the original video, we will not process the original video at all
and also not reencode it. In this case,
result.output.url will point to the original video that was passed to the editor, if available.
If you want to ensure that the original video is always reencoded, even if no modifications have
been made to it, you can set
true, in which case
always point to a newly generated video.
In order to access a user's camera roll we have to request access using the
We check the status that is passed to the closure to ascertain whether authorization has been granted and handle the case when it is denied.
In a production app you would display an alert explicitly requesting that the user edit their settings to grant access.
Move to Shared Library#
Once access has been granted, we can perform changes in the shared video library. To that end we create a
PHAssetCreationRequest and invoke the
addResource method passing the video URL and options.
If the options contain
shouldMoveFile = true, this moves the video file to the shared library instead of copying it and saving the copy avoiding the need to manually delete the exported video file.
Note that the check we perform beforehand whether the video file was passed without changes handles a quirk of the simulator and is unnecessary in production.
Finally, we handle the completion of the change operation. Accessing the status arguments
error allows us to log errors and display messages to our users before we dispatch to main queue and dismiss the editor.