addResourceWithType not working for RAW + JPEG (restoring a RAW+JPEG asset not possible)

Hi,


this question refers to classes PHAssetCreationRequest & PHAssetResource, which are new in iOS 9.

From the documentation:

"This class (PHAssetCreationRequest) works in terms of the raw data resources that together form an asset, so you can use it together with the PHAssetResource class to perform a complete copy (or backup and restore) of an asset’s underlying resources."


I tried the Backup & Restore procedure for a RAW+JPEG PHAsset, which has been imported from a camera using the Camera Connection Kit.


1) Backing up works fine.

For a JPEG+RAW asset the method assetResourcesForAsset: of PHAssetResource returns

<PHAssetResource: 0x126d83f60> type=photo uti=public.jpeg filename=P1080727.JPG assetLocalIdentifier=0C56E8A5-ECAB-4474-91E4-2688885A6CF6/L0/001,
<PHAssetResource: 0x128803fa0> type=photo_alt uti=com.panasonic.rw2-raw-image filename=P1080727.RW2 assetLocalIdentifier=0C56E8A5-ECAB-4474-91E4-2688885A6CF6/L0/001)

So the resource type for the JPEG is PHAssetResourceTypePhoto, while the resource type for the RAW is PHAssetResourceTypeAlternatePhoto


2) Trying to restore the RAW+JPEG asset using addResourceWithType fails.

The follwing code is used to perform the restore:

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

  PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAsset];
  [request addResourceWithType:PHAssetResourceTypePhoto fileURL:[[NSBundle mainBundle] URLForResource:@"P1080727" withExtension:@"JPG"] options:nil];
  [request addResourceWithType:PHAssetResourceTypeAlternatePhoto fileURL:[[NSBundle mainBundle] URLForResource:@"P1080727" withExtension:@"RW2"] options:nil];

   } completionHandler:^(BOOL success, NSError * _Nullable error) {
       NSLog(@"PHPhotoLibrary performChanges result: Success: %i, Error: %@",success,error);
}];


The performChanges-Block completes with a Cocoa Error -1 without any further information.

So it does not seem to be possible (in contrast to the documentation) to restore a PHAsset with both a JPEG and RAW resource file.

Additonal note:

[PHAssetCreationRequest supportsAssetResourceTypes:@[@(PHAssetResourceTypePhoto),@(PHAssetResourceTypeAlternatePhoto)]];

also returns false. Also using other AssetResourceTypes I couldn't find any combinations, for which this function returns true.

I reported the issue also as radar 22701890. The behaviour is the same on iOS 9 GM and iOS 9 Beta 1.


Am I missinterpreting something on how these classes should be used ?



Cheers,


Hendrik

addResourceWithType not working for RAW &#43; JPEG (restoring a RAW&#43;JPEG asset not possible)
 
 
Q