October 2013
Intermediate to advanced
1053 pages
28h 7m
English
You want to store a video accessible through a URL, such as a video in your application bundle, to the photo library.
Use the writeVideoAtPathToSavedPhotosAlbum:completionBlock:
instance method of ALAssetsLibrary:
#import "AppDelegate.h"#import <AssetsLibrary/AssetsLibrary.h>@interfaceAppDelegate()@property(nonatomic,strong)ALAssetsLibrary*assetsLibrary;@end@implementationAppDelegate-(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions{self.assetsLibrary=[[ALAssetsLibraryalloc]init];NSURL*videoURL=[[NSBundlemainBundle]URLForResource:@"MyVideo"withExtension:@"MOV"];if(videoURL!=nil){[self.assetsLibrarywriteVideoAtPathToSavedPhotosAlbum:videoURLcompletionBlock:^(NSURL*assetURL,NSError*error){if(error==nil){NSLog(@"no errors happened");}else{NSLog(@"Error happened while saving the video.");NSLog(@"The error is = %@",error);}}];}else{NSLog(@"Could not find the video in the app bundle.");}returnYES;}
The Assets Library framework is a convenient bridge between developers and the photo library. As mentioned in Recipe 15.6, the iOS SDK provides you with built-in GUI components that you can use to access the contents of the photo library. However, you might sometimes require direct access to these contents. In such instances, you can use the Assets Library framework.
After allocating and initializing the Assets Library ...
Read now
Unlock full access