将视频放入相机胶卷中的一个特定相册中

时间:2015-11-04 07:25:08

标签: ios objective-c alassetslibrary avassetwriter phasset

我正在我的相机胶卷中创建一个特定的相册..但是对于我的每一次运行,它在我的相机胶卷中创建了一个新专辑,而不是将视频放在同一个专辑中..想法?

__block PHObjectPlaceholder *assetCollectionPlaceholder;

    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{


        // Create new album.
        [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
            PHAssetCollectionChangeRequest *createAlbumRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"Eye Movement"];
            assetCollectionPlaceholder = createAlbumRequest.placeholderForCreatedAssetCollection;
        } completionHandler:^(BOOL success, NSError *error) {
            if (success) {
                PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[assetCollectionPlaceholder.localIdentifier] options:nil];
                PHAssetCollection *assetCollection = fetchResult.firstObject;

                // Add it to the photo library
                [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
                    PHAssetChangeRequest* createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:outputFileURL];
                    PHAssetCollectionChangeRequest* assetRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:assetCollection];
                     [assetRequest addAssets:@[[createAssetRequest placeholderForCreatedAsset]]];
                    //PHAssetCollectionChangeRequest *assetCollectionChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:assetCollection];
                    //[assetCollectionChangeRequest addAssets:@[[createAssetRequest placeholderForCreatedAsset]]];
                } completionHandler:^(BOOL success, NSError *error) {
                    if (!success) {
                        NSLog(@"Error creating asset: %@", error);
                    }
                }];
            } else {
                //NSLog(@"Error creating album: %@", error);
                NSLog(@"didFinishRecordingToOutputFileAtURL - success for ios9");
            }
        }];

0 个答案:

没有答案