-
-
Save gunantosteven/fd583754ee81eb482f82899fa0004f5a to your computer and use it in GitHub Desktop.
Be Careful with "UI API called on a background thread"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.view.makeToastActivity(.center) | |
DispatchQueue.global(qos: .background).async { | |
if let url = URL(string: self.photo.url), | |
let urlData = NSData(contentsOf: url) | |
{ | |
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]; | |
let filePath="\(documentsPath)/tempFile.mp4" | |
urlData.write(toFile: filePath, atomically: true) | |
PHPhotoLibrary.shared().performChanges({ | |
let assetChangeRequest = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: URL(fileURLWithPath: filePath)) | |
let albumChangeRequest = PHAssetCollectionChangeRequest(for: CustomPhotoAlbum.sharedInstance.assetCollection) | |
albumChangeRequest!.addAssets([assetChangeRequest!.placeholderForCreatedAsset!] as NSArray) | |
}) { completed, error in | |
if completed { | |
print("Video is saved!") | |
} | |
DispatchQueue.main.async { | |
self.view.hideToastActivity() | |
self.view.makeToast(self.messages.social_downloaded, duration: 2.0, position: .center) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment