Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将视频放在相机卷中的一个特定相册中_Ios_Objective C_Alassetslibrary_Avassetwriter_Phasset - Fatal编程技术网

Ios 将视频放在相机卷中的一个特定相册中

Ios 将视频放在相机卷中的一个特定相册中,ios,objective-c,alassetslibrary,avassetwriter,phasset,Ios,Objective C,Alassetslibrary,Avassetwriter,Phasset,我正在我的相机卷中创建一个特定的相册。。但对于我的每一次跑步,它都是在我的相机卷中创建一个新的相册,而不是将视频放在同一个相册中。。想法 __block PHObjectPlaceholder *assetCollectionPlaceholder; [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ // Create new album. [[PHPhotoLibrary sharedPh

我正在我的相机卷中创建一个特定的相册。。但对于我的每一次跑步,它都是在我的相机卷中创建一个新的相册,而不是将视频放在同一个相册中。。想法

__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");
            }
        }];

你必须先检查相册是否已创建,然后告诉应用程序创建相册(如果不存在)

__block PHFetchResult *photosAsset;
__block PHAssetCollection *collection;
__block PHObjectPlaceholder *placeholder;

// Find the album
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", @"Your Album Name Here"];
collection = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum
                                                      subtype:PHAssetCollectionSubtypeAny
                                                      options:fetchOptions].firstObject;
// Create the album
if (!collection)
{
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        PHAssetCollectionChangeRequest *createAlbum = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"Your Album Name Here"];
        placeholder = [createAlbum placeholderForCreatedAssetCollection];
    } completionHandler:^(BOOL success, NSError *error) {
        if (success)
        {
            PHFetchResult *collectionFetchResult = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[placeholder.localIdentifier]
                                                                                                        options:nil];
            collection = collectionFetchResult.firstObject;
        }
    }];
}