Background Assets: BAURLDownload is finish, but the file cannot be read, the file does not exist

My Background Assets extension arranges to download image resources, as follows:

NSURL *assetURL = [NSURL URLWithString:@"https://***.png”];
NSUInteger assetSize = 6849;
switch (contentRequest) {
case BAContentRequestInstall:
case BAContentRequestUpdate:
{
BAURLDownload *essentialDownload = [[BAURLDownload alloc] initWithIdentifier:@"YYBADAsset"
request:[NSURLRequest requestWithURL:assetURL]
essential:true
fileSize:assetSize
applicationGroupIdentifier:appGroupIdentifier
priority:BADownloaderPriorityDefault];
[downloadsToSchedule addObject:essentialDownload];
break;
}
}

At the same time, the finishedWithFileURL method is implemented as follows:

- (void)backgroundDownload:(BADownload *)download finishedWithFileURL:(NSURL *)fileURL
{
NSLog(@"BackgroundAssetsTest extension finishedWithFileURL:%@ forDownlad:%@",fileURL,download.identifier);
NSLog(@"BackgroundAssetsTest extension finishedWithManifestURLExist:%@",@([[NSFileManager defaultManager] fileExistsAtPath:fileURL.absoluteString]));
}

And then use tools to trigger events, xcrun backgroundassets-debug --app-bundle-id com.luph.mytest --device-id 00008020-000A04xxF0002E --simulate --app-install

The following log is observed through the console:

BackgroundAssetsTest extension finishedWithFileURL:file:///private/var/mobile/Containers/Shared/AppGroup/1D051E06-E597-4670-969A-38ECA52C4F7A/Library/C aches/com.apple.BackgroundAssets/BAFile-5152AFB2.tmp forDownlad:YYBADAsset

BackgroundAssetsTest extension finishedWithManifestURLExist:0

What's the problem? Did I set the size of BAURLDownload to be different from the actual download size? Or the wrong way to determine the existence of the file?

Answered by Frameworks Engineer in 758799022

Instead of:

[[NSFileManager defaultManager] fileExistsAtPath:fileURL.absoluteString]

Use:

[[NSFileManager defaultManager] fileExistsAtPath:fileURL.path]

absoluteString will create a string that includes the URL's scheme (i.e. file:///path/to/file), which will not work with [NSFileManager fileExistsAtPath].

Accepted Answer

Instead of:

[[NSFileManager defaultManager] fileExistsAtPath:fileURL.absoluteString]

Use:

[[NSFileManager defaultManager] fileExistsAtPath:fileURL.path]

absoluteString will create a string that includes the URL's scheme (i.e. file:///path/to/file), which will not work with [NSFileManager fileExistsAtPath].

Background Assets: BAURLDownload is finish, but the file cannot be read, the file does not exist
 
 
Q