December 2012
Intermediate to advanced
834 pages
27h
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:
-(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.");}self.window=[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];self.window.backgroundColor=[UIColorwhiteColor];[self.windowmakeKeyAndVisible];returnYES;}
In the example, assetsLibrary
is a property of type ALAssetsLibrary. Although this example
allocates and initializes this property in the app delegate, you do not
necessarily have to use Assets Library objects in your app delegate. You
can allocate, initialize, and use them anywhere in your application that
you find most appropriate.
The Assets Library framework is a convenient bridge between developers and the Photo Library. As mentioned ...
Read now
Unlock full access