【问题标题】:Save image to a specific photo album with photo framework ios 8使用照片框架 ios 8 将图像保存到特定相册
【发布时间】:2015-12-01 14:06:09
【问题描述】:

我刚刚使用此代码创建了一个新相册:

 [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
     {
         //Checks for App Photo Album and creates it if it doesn't exist
         PHFetchOptions *fetchOptions = [PHFetchOptions new];
         fetchOptions.predicate = [NSPredicate predicateWithFormat:@"title == %@", @"ChameleonSensors"];
         PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:fetchOptions];

         if (fetchResult.count == 0)
         {
             //Create Album
             PHAssetCollectionChangeRequest *albumRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"ChameleonSensors"];
         }

     }

      completionHandler:^(BOOL success, NSError *error)
     {
         NSLog(@"Log here...");

         if (!success) {
             NSLog(@"Error creating album: %@", error);
         }else{
             NSLog(@"Perfecto");
         }
     }];

没关系,但现在我需要将照片保存在此相册中。

我正在使用 Objective-c 和照片框架。

谢谢

【问题讨论】:

    标签: objective-c iphone ios8 photo


    【解决方案1】:

    您应该将资产添加到 albumRequest

        //Create Album
        PHAssetCollectionChangeRequest *albumRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"ChameleonSensors"];
        PHAssetChangeRequest *createImageRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[UIImage imageNamed:@"test"]];
        [albumRequest addAssets:@[createImageRequest.placeholderForCreatedAsset]];
    

    【讨论】:

    • 是否有可能知道该图像的保存路径?,
    • 是的,placeholderForCreatedAsset 始终具有与其所代表的资产、集合或集合列表相同的本地标识符。要查找与占位符对应的对象,请读取占位符的 localIdentifier 属性并使用它来获取实际对象。
    • 我得到了这个标识符:9C41BF95-A9C5-498B-AFFA-6D9CF6B56C21/L0/001。是这样吗?,现在如何获取路径?
    • 我找到的唯一方法是here。使用requestContentEditingInputWithOptions: 并从PHContentEditingInput 获取fullSizeImageURL
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-20
    • 2015-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多