ios - Unable to Save Video to Camera Roll (Objective C) -
So I'm trying to complete it for some time, but unfortunately, of the solutions posted on the stack Nobody, or the people who tried to write myself, do the work. I am creating an application that allows users to take pictures and videos, and to save them to other users. I am using AWS services to save content. Although returning using YouTube using NSLog, YouTube shows the video when I copy / paste it in a browser, refuses to save it to the camera's roll, but saving the pictures works just fine.
So far I have made the following efforts:
- (minus) Image Picture Controls: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {if ([Media Type Ikwoltostring: (Ansstiing *) Kuttaipmovia]) {Ansdrael * movie URL = [information object Foreki: Uaimajepikantrolrmeediauarel]; Elasette Library * Library = [[Elsace Library Library] init]; [Library writeVideoAtPathToSavedPhotosAlbum: movieUrl completionBlock: ^ (NSURL * assetURL, NSError * error) {if (error) {NSLog (@ "CameraViewController: Error saving the movie:% @ {imagePickerController}", error); } Other {nslog (@ "url:% @", asset url); }}]; }}
Even:
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (self.post.mediaUrl)) {UISaveVideoAtPathToSavedPhotosAlbum (self.post.mediaUrl, self, @selector (Video: finishedSavingWithError: contextInfo :), @ selector (video: finishedSavingWithError: contextInfo :)); } Else {NSLog (@ "Incompatible File Apparently"); }
Any advice? Thanks!
* Updated to April 6, 2016 for using modern settings
< P> Import the following wherever you do this method: #import & lt; AssetsLibrary / AssetsLibrary.h & gt; @import photos
Then call the method as the following:
[yourClass saveMedia: (* your image *) Video: (* Your video url *)]
Hope this helps people, feel free to comment with the questions.
+ (zero) Save Media: (UIImage *) Image Video: (NSURL *) Video_url {if (Image) {if (image!) {Return; } [[PHPhotoLibrary Sajafoto Library] performance Krensnchar: ^ {PHAssetChangeRequest * changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage: image]; NSLog (@ "% @", changeRequest.description); } Complete Handler: ^ (Bell Success, NSERR * Error) {If (Success) {NSLog (@ "saved"); } And {nslog (@ "something wrong"); }}]; } Else if (video_url) {if ([video_url absolustString]. Length <1) {return; } NSLog (@ "source would:% @", video_url.absoluteString); NSURL * sourceURL = video_url; If ([[NSFileManager defaultManager] fileExistsAtPath: [video_url absoluteString]]) {[[[ALAssetsLibrary alloc] init] writeVideoAtPathToSavedPhotosAlbum: video_url completionBlock: ^ (NSURL * assetURL, NSError * error) {if (assetURL) {NSLog (@ "saved bottom "); } And {nslog (@ "something wrong"); }}]; } Else {NSURLSessionTask * download = [[NSURL session sharing session] downloadTaskWithURL: sourceURL completionHandler: ^ (NSURL * Location, NSURLResponse * reaction, NSError * error) {if (error) {NSLog (@ "save error:% @", Error localizedDescription); Return; } NSURL * documentsURL = [[[NSFileManager default manager] URLForDirectory: NSDocumentDirectory inDomains: NSUserDomainMask] firstObject]; NSURL * tempURL = [documentsURL URLByAppendingPathComponent: [sourceURLLast Text Company]]; [[NSFileManager defaultManager] moveItemAtURL: place toURL: tempURL error: zero]; [[PHPhotoLibrary Sajafoto Library] changes: ^ {PHAssetChangeRequest * changeRequest = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL: tempURL]; NSLog (@ "% @", changeRequest.description); } Complete Handler: ^ (Bell Success, NSERR * Error) {If (Success) {NSLog (@ "saved"); [[NSFileManager defaultManager] removeItemAtURL: tempURL error: zero]; } Other {NSLog (@ "Something Wrong% @", Error. Localized Descriptration); [[NSFileManager defaultManager] removeItemAtURL: tempURL error: zero]; }}]; }]; [resume download]; }}}
Comments
Post a Comment