Skip to content

Instantly share code, notes, and snippets.

@victusfate
Last active September 29, 2020 09:43
Show Gist options
  • Save victusfate/8969a70e82c00ae448a7 to your computer and use it in GitHub Desktop.
Save victusfate/8969a70e82c00ae448a7 to your computer and use it in GitHub Desktop.
slow export to photo library
Mark Essel10-Aug-2015 02:41 PM
Summary:
The issue specifically arises when a user has iCloud photo backup enabled, and attempts to export a substantial video to the photo library (the longer the video the longer the delay, exponentially slower)
https://gist.github.com/victusfate/8969a70e82c00ae448a7
Steps to Reproduce:
1. turn on icloud photo backup
2. run the attached code snippet in an app for a given videoURL
3. when it takes tens of seconds or minutes for a 1min+ video you have recreated the issue
Expected Results:
I expect the changeRequest to take seconds (max dependent on file size) to add an existing local video to the local photo library
Actual Results:
It can sometimes take minutes to add a local video to the photo library
Version:
Version 6.4 (6E35b)
Notes:
Configuration:
code snippet when run on device (dev mode is fine)
Attachments:
func exportAssetToPhotoLibrary(videoURL: NSURL, _ exportedAsset: (localIdentifier: String) -> Void) {
var localIdentifier = ""
var startTime = NSDate.timeIntervalSinceReferenceDate()
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
let assetRequest = PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(videoURL)
let assetPlaceholder = assetRequest.placeholderForCreatedAsset
localIdentifier = assetPlaceholder.localIdentifier
},
completionHandler: { success, error in
var elapsedTime: NSTimeInterval = NSDate.timeIntervalSinceReferenceDate() - startTime
NSLog("exported cameo video to photo library \(elapsedTime)")
exportedAsset(localIdentifier: localIdentifier)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment