I've added a background downloads extension to my app and added device console logging to every method in the placeholder code created by XCode, and Setting a breakpoint, then installed the app to the phone.
When I run the following command:
xcrun backgroundassets-debug --app-bundle-id com.myCompany.myApp --device-id 00008110-001E0DDA0AB8801E --simulate --app-update
prompt: Application was updated event was sent for app identifier: (com.myCompany.myApp).
But the break point did not enter。Nothing is sent, and there is no log output
How do I set breakpoints in the extension for debugging?
Post
Replies
Boosts
Views
Activity
Background Assets are integrated into our online Appstore. However, after launching the APP, we collected many crashes of Background Assets framework through our crash system.
1、BADownloadManager.sharedManager.fetchCurrentDownloadsWithCompletionHandler. Then, I am reinitiating the tasks through startForegroundDownload. However, occasionally there is a crash with EXC_BREAKPOINT
[BADownloadManager.sharedManager fetchCurrentDownloadsWithCompletionHandler:^(NSArray<BADownload *> * _Nonnull downloads, NSError * _Nullable error) {
if (error){
return;
}
for (BADownload *download in downloads) {
if ([urlList containsObject:download.identifier]){
if (download.state == BADownloadStateFailed) {
return;
}
NSError *downloadError;
BOOL succes = [BADownloadManager.sharedManager startForegroundDownload:download error:&downloadError];
if (downloadError) {
LogError(BADownloadLog,@"startForegroundDownload url:%@ error:%@",download.identifier,downloadError);
}else if(succes){
LogInfo(BADownloadLog,@"startForegroundDownload:%@",download.identifier);
[self addDowdloadingUrl:download.identifier];
}
}
}
}];
The following crashes exist:
Thread 3 (crashed)
0 BackgroundAssets!-[BADownloadManager startForegroundDownload:error:] + 0x100
Found by: given as instruction pointer in context
1 BackgroundAssets!-[BADownloadManager startForegroundDownload:error:] + 0xe0
Found by: previous frame's frame pointer
2 YYMobile!__46-[YYBADownloadManager executeDownload:finish:]_block_invoke [YYBADownloadManager.m : 180 + 0xc]
Found by: previous frame's frame pointer
3 libdispatch.dylib!_dispatch_call_block_and_release + 0x1c
Found by: previous frame's frame pointer
4 libdispatch.dylib!_dispatch_client_callout + 0x10
Found by: previous frame's frame pointer
5 libdispatch.dylib!_dispatch_lane_serial_drain + 0x298
Found by: previous frame's frame pointer
6 libdispatch.dylib!_dispatch_lane_invoke + 0x17c
Found by: previous frame's frame pointer
7 libdispatch.dylib!_dispatch_workloop_worker_thread + 0x284
Found by: previous frame's frame pointer
8 libsystem_pthread.dylib!_pthread_wqthread + 0x11c
Found by: previous frame's frame pointer
See attachment "iOS.crash" for the complete crash file.
iOS.crash
Ask what, do I need to use exclusive control when accessing BADownload?
2、Handling failed callbacks in background download extension, rearranging necessary resources crashed
- (void)backgroundDownload:(BADownload *)download failedWithError:(NSError *)error
{
// Extension was woken because a download failed.
// A download can be rescheduled with BADownloadManager if necessary.
if (![download isKindOfClass:[BAURLDownload class]]) {
return;
}
if (download.isEssential){
BADownload *nonEssential = [download copyAsNonEssential];
[BADownloadManager.sharedManager scheduleDownload:nonEssential error:nil];
}
}
Have a crash:
hread 1 Crashed:
0 BackgroundAssets 0x0000000245b47dac -[BADownload setPriority:] + 176 (BADownload.m:249)
1 BackgroundAssets 0x0000000245b47bb4 -[BADownload copyWithZone:] + 188 (BADownload.m:217)
2 BackgroundAssets 0x0000000245b46db0 -[BAURLDownload copyWithZone:] + 52 (BAURLDownload.m:127)
3 BackgroundAssets 0x0000000245b47f7c -[BADownload copyAsNonEssential] + 20 (BADownload.m:368)
4 YYBackgroundDownload 0x0000000100de8a88 0x100de4000 + 19080
5 BackgroundAssets 0x0000000245b3fd50 __88-[BADownloaderExtensionConnection backgroundDownload:failedWithError:completionHandler:]_block_invoke + 56 (BADownloaderExtensionConnection.m:178)
6 libdispatch.dylib 0x00000001d8080320 _dispatch_call_block_and_release + 32 (init.c:1518)
7 libdispatch.dylib 0x00000001d8081eac _dispatch_client_callout + 20 (object.m:560)
8 libdispatch.dylib 0x00000001d8089534 _dispatch_lane_serial_drain + 668 (inline_internal.h:2640)
9 libdispatch.dylib 0x00000001d808a0a4 _dispatch_lane_invoke + 384 (queue.c:3966)
10 libdispatch.dylib 0x00000001d8094cdc _dispatch_workloop_worker_thread + 648 (queue.c:6913)
11 libsystem_pthread.dylib 0x0000000230547ddc _pthread_wqthread + 288 (pthread.c:2618)
12 libsystem_pthread.dylib 0x0000000230547b7c start_wqthread + 8 (:-1)
Details see attachment
2023-09-19_09-46-22.4511_+0800-6c5f4b24bec7c04256c852d7a008978a886c15a3.crash
I am starting the app and fetching the current downloading tasks through BADownloadManager.sharedManager.fetchCurrentDownloadsWithCompletionHandler. Then, I am reinitiating the tasks through startForegroundDownload. However, occasionally there is a crash with EXC_BREAKPOINT
[BADownloadManager.sharedManager fetchCurrentDownloadsWithCompletionHandler:^(NSArray<BADownload *> * _Nonnull downloads, NSError * _Nullable error) {
if (error){
return;
}
for (BADownload *download in downloads) {
if ([urlList containsObject:download.identifier]){
if (download.state == BADownloadStateFailed) {
return;
}
NSError *downloadError;
BOOL succes = [BADownloadManager.sharedManager startForegroundDownload:download error:&downloadError];
if (downloadError) {
LogError(BADownloadLog,@"startForegroundDownload url:%@ error:%@",download.identifier,downloadError);
}else if(succes){
LogInfo(BADownloadLog,@"startForegroundDownload:%@",download.identifier);
[self addDowdloadingUrl:download.identifier];
}
}
}
}];
Crash stack:
Crash reason: EXC_BREAKPOINT / EXC_ARM_BREAKPOINT
Crash address: 0x21be8f638
Process uptime: 2 seconds
Thread 3 (crashed)
0 BackgroundAssets!-[BADownloadManager startForegroundDownload:error:] + 0x100
Found by: given as instruction pointer in context
1 BackgroundAssets!-[BADownloadManager startForegroundDownload:error:] + 0xe0
Found by: previous frame's frame pointer
2 YYMobile!__46-[YYBADownloadManager executeDownload:finish:]_block_invoke [YYBADownloadManager.m : 180 + 0xc]
Found by: previous frame's frame pointer
3 libdispatch.dylib!_dispatch_call_block_and_release + 0x1c
Found by: previous frame's frame pointer
4 libdispatch.dylib!_dispatch_client_callout + 0x10
Found by: previous frame's frame pointer
5 libdispatch.dylib!_dispatch_lane_serial_drain + 0x298
Found by: previous frame's frame pointer
6 libdispatch.dylib!_dispatch_lane_invoke + 0x17c
Found by: previous frame's frame pointer
7 libdispatch.dylib!_dispatch_workloop_worker_thread + 0x284
Found by: previous frame's frame pointer
8 libsystem_pthread.dylib!_pthread_wqthread + 0x11c
Found by: previous frame's frame pointer
The crash occurred at BOOL succes = [BADownloadManager.sharedManager startForegroundDownload:download error:&downloadError];
I need to convert a Super Resolution model to a mlmodel, but the input shape of the model is designed in the format [batch_size, height, width, 3]. Then I will convert with the following code
model = hub.load("https://tfhub.dev/captain-pool/esrgan-tf2/1")
tf.saved_model.save(model, "esrgan_saved_model")
input_type = ct.ImageType(shape=(1 , 192, 192, 3),color_layout=ct.colorlayout.RGB)
output_type = ct.ImageType(color_layout=ct.colorlayout.RGB)
mlmodel = ct.convert(
'./esrgan_saved_model',
inputs=[input_type],
outputs=[output_type],
source="tensorflow")
mlmodel.save('esrgan.mlmodel')
I got an error
Shape of the RGB/BGR image output, must be of kind (1, 3, H, W), i.e., first two dimensions must be (1, 3)
ImageType only seems to support input and output from [batch_size, 3, height, width]. What should I do to convert the model of format [batch_size, height, width, 3] to mlmodel?
Background asstes are triggered before the APP is launched. At this time, if the current device is not connected to the WIFI network, it will directly consume the operator's network traffic.
Is there any way to limit this in order to avoid disputes over fees arising from the consumption of users' non-wifi traffic without their knowledge?
For example, after extension is triggered, determine the network status when scheduling downloads?
The BAEssentiaMaxInstallSize key in the plist file indicates the installed maximum size of the necessary resources. Is this size the uncompression size, and is this size included in the size of the BAMaxInstallSize key?
Is BAEssentialDownloadAllowance included in BADownloadAllowance?
I wrote the following code to schedule the download in extension:
AURLDownload *essentialDownload = [[BAURLDownload alloc] initWithIdentifier:url
request:[NSURLRequest requestWithURL:assetURL]
essential:true
fileSize:assetSize
applicationGroupIdentifier:YYBASharedSettings.appGroupIdentifier
priority:BADownloaderPriorityDefault];
NSLog(@"BackgroundAssetsTest extension Schedule essentialDownload url:%@",url);
and the delegate callback is implemented as follows:
- (void)backgroundDownload:(BADownload *)download failedWithError:(NSError *)error
{
NSLog(@"BackgroundAssetsTest extension failedWithError: %@",error);
}
The console outputs the following error:
BackgroundAssetsTest extension failedWithError: Error Domain=BAErrorDomain Code=202 "The requested URL is not permitted to be downloaded until the application is launched." UserInfo={NSLocalizedFailureReason=The requested URL is not permitted to be downloaded until the application is launched.}
What's the problem?
Scheduled downloads can only be triggered by launching the APP?
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?
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?
On Chinese devices, the APP requires the authorization of network access. On the newly installed APP, if the user has not authorized it, will Background Assets work normally?
I have the manifestURL set up in the info.plist.
Write the following code for extension
- (NSSet<BADownload *> *)downloadsForRequest:(BAContentRequest)contentRequest
manifestURL:(NSURL *)manifestURL
extensionInfo:(BAAppExtensionInfo *)extensionInfo
{
[BADownloadManager sharedManager].delegate = self;
NSLog(@"BackgroundAssetsTest extension downloadsForRequestWithManifestURLExist:%@",@([[NSFileManager defaultManager] fileExistsAtPath:self.manifestURL.absoluteString]));
NSLog(@"BackgroundAssetsTest extension downloadsForRequest: %@",manifestURL);
NSError *cfgError;
NSString *config = [NSString stringWithContentsOfFile:self.manifestURL.absoluteString encoding:NSUTF8StringEncoding error:&cfgError];
NSLog(@"BackgroundAssetsTest extension downloadsForRequestCfg:%@ error:%@",config,cfgError);
....
}
Trigger using the backgroundassets-debug tool. But the manifestURL file of the extension delegate callback does not exist.
Viewing console.app Logs:
BackgroundAssetsTest extension downloadsForRequestWithManifestURLExist:0
BackgroundAssetsTest extension downloadsForRequest: file:///var/tmp/com.apple.backgroundassets.downloadstaging/com.my.bundleid/994c0d0f-17c0-44b3-8e92-144927701b9c.json
BackgroundAssetsTest extension downloadsForRequestCfg:(null) error:Error Domain=NSCocoaErrorDomain Code=260 "The file “994c0d0f-17c0-44b3-8e92-144927701b9c.json” couldn’t be opened because there is no such file." UserInfo={NSFilePath=file:///var/tmp/com.apple.backgroundassets.downloadstaging/com.my.bundleid/994c0d0f-17c0-44b3-8e92-144927701b9c.json, NSUnderlyingError=0x103f06e90 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
What happens when I'm supposed to read the file for parsing, but it doesn't exist!!
Background Assets
how to test your extension and to simulate its entry points.
If the resource downloaded through BADownloadManager has been completed, will BADownloadManager download the same resource repeatedly? If not, does the developer have to keep track of the downloaded resources? So that when the extension is triggered, the query ignores the downloaded resources
On iOS15 beta, Use -requestImageForAsset: targetSize: contentMode: options: resultHandler, callback UIImage * result is nil,
and PHImageErrorKey = "Error Domain=PHPhotosErrorDomain Code=-1 "(null)""