Background Assets Failed to move manifestURL to APP group

After receiving manifestURL in extension, I try to move it to the shared directory of APP group, as follows:

NSURL *url = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:self.appGroupIdentifier];
    NSURL *storageURL = [url URLByAppendingPathComponent:@"YYBAResCache" isDirectory:YES];
    BOOL isDirectory;
    BOOL isExists = [NSFileManager.defaultManager fileExistsAtPath:storageURL.path isDirectory:&isDirectory];
    NSError *error = nil;
    if (!isExists || !isDirectory) {
        [NSFileManager.defaultManager createDirectoryAtURL:storageURL withIntermediateDirectories:YES attributes:@{NSFilePosixPermissions: [NSNumber numberWithShort:0777]} error:&error];
    }
    if (error){
        NSLog(@"Failed to create session storage directory:%@",error);
    }

NSURL *localManifestURL = [sessionStorageURL URLByAppendingPathComponent:@"manifest.json"];

Next, move the file:

NSError *error;

[NSFileManager.defaultManager moveItemAtURL:manifestURL toURL:localManifestURL error:&error];
if (error) {
        NSLog(@"BackgroundAssetsTest extension saveMainifest:%@ to %@ error:%@",manifestURL,YYBASharedSettings.localManifestURL,error);
    }

But I still received an error:

BackgroundAssetsTest extension saveMainifest:file:///var/tmp/com.apple.backgroundassets.downloadstaging/com.devinprogress2021/2cf0ae65-3058-4522-80d5-f4d76747ad15.json to file:///private/var/mobile/Containers/Shared/AppGroup/F466C6BA-35D7-4115-8D8E-E1726E3D3696/YYBAResCache/manifest.json 
error:Error Domain=NSCocoaErrorDomain Code=513 "“2cf0ae65-3058-4522-80d5-f4d76747ad15.json” couldn’t be moved because you don’t have permission to access “YYBAResCache”." UserInfo={NSSourceFilePathErrorKey=/var/tmp/com.apple.backgroundassets.downloadstaging/com.yy.yymobile.devinprogress2021/2cf0ae65-3058-4522-80d5-f4d76747ad15.json, NSUserStringVariant=(
    Move
), NSDestinationFilePath=/private/var/mobile/Containers/Shared/AppGroup/F466C6BA-35D7-4115-8D8E-E1726E3D3696/YYBAResCache/manifest.json, NSFilePath=/var/tmp/com.apple.backgroundassets.downloadstaging/com.devinprogress2021/2cf0ae65-3058-4522-80d5-f4d76747ad15.json, NSUnderlyingError=0x14520d2d0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

why?

Accepted Reply

The manifest file is managed by the system, and your app/extension doesn't have write access to it. Your options are to parse the file in its current location, or copy it to a location you manage within your container.

Replies

The manifest file is managed by the system, and your app/extension doesn't have write access to it. Your options are to parse the file in its current location, or copy it to a location you manage within your container.