IOS 8 Photo Library - Error adding asset using PHAssetChangeRequest

When I try to create a photo resource using, [PHAssetChangeRequest creationReqeustForAssetFromImageAtFileURL:]

I get the "Operation not allowed" error. I am trying to copy another photo from the Photo Library, first getting the path to the first photo.

The function works as expected when run on the emulator, but does not work when I run it on the device itself. The emulator and device are running iOS 8.3. The iPad is configured to store photos on iCloud, the emulator is not.

My code snippet

    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
          PHAssetChangeRequest *assetChangeRequest = 
                   [PHAssetChangeReques creationRequestForAssetFromImageAtFileURL:currentImagePath];
    } completionHandler:^(BOOL success, NSError *error) {
       if (!success) {
           NSLog(@"Error creating asset: %@", error);
       }

      

currentImagePath

comes from [PHImageManager requesstImageDataForAsset:]

by providing an asset of the photo I am trying to copy. The path looks like the one shown on the iPad itself:

     file:///var/mobile/Media/DCIM/101IMPRT/IMG_1258.JPG

      

It looks like this when I run it in the emulator:

     file:///Users/<my-name>/Library/Developer/CoreSimulator/Devices/<long UUID-type code>/data/Media/PhotoData/Mutations/DCIM/100APPLE/IMG_0002/Adjustments/FullSizeRender.jpg

      

Getting an error when requesting create:

error message

Unable to create data from file Error Domain = NSCocoaErrorDomain Code = 257 "Operation cannot be performed. (Cocoa error 257.)" UserInfo = 0x17046ac40 {NSFilePath = / var / mobile / media / DCIM / 100APPLE / IMG_0042.JPG, NSUnderlying02480a = 0x17 "The operation could not be completed. The operation is not allowed"}

Interestingly, the create request succeeded on all platforms if I use UIImage * with the function [PHAssetChangeRequest creationReqeustForAssetFromImage:]

.

I would be grateful if someone can explain what is going on. Is it related to storing photos in the cloud? I tried to disable iCloud for Photos on iPad, but I still get the same behavior.

+3


source to share


1 answer


For reference, if you are using Cloud, you may need to use networkAccessAllowed: Bool:

. This will check if you can download the image from the cloud if needed.

I'm not sure exactly in the context of your problem, because this post is a bit unclear. You checked the dictionary resultHandler

for errors in the function call

func requestImageForAsset(_ asset: PHAsset!,
               targetSize targetSize: CGSize,
              contentMode contentMode: PHImageContentMode,
                  options options: PHImageRequestOptions!,
            resultHandler resultHandler: ((UIImage!,
                [NSObject : AnyObject]!) -> Void)!) -> PHImageRequestID

      



Before editing an asset, use the method canPerformEditOperation

to find out if the asset allows editing.

"To edit an image or video content, first start a content editing session using the method requestContentEditingInputWithOptions:completionHandler:

. You do the content editing by setting contentEditingOutput

the change request property in the change block. For information on changing the resource content, see the PHAsset class reference .

0


source







All Articles