App is crashing on only iOS 13 in the background mode
Asked Answered
U

1

-2

The app is crashing only on iOS 13 and when I saw the detailed report, Reports are mentioning the app was in the background when it was crashed. No reference of the line of code mentioned in the crash logs where I can find the line which is causing the crash. Please suggest if anyone else also face such type of problem ever.

Crashed: com.apple.main-thread

EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000f5e5f9c3c

Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x1aed79d10 objc_opt_respondsToSelector + 20
1  Foundation                     0x1af423588 _NSDescriptionWithStringProxyFunc + 56
2  CoreFoundation                 0x1aefdc534 __CFStringAppendFormatCore + 7960
3  CoreFoundation                 0x1aefddb10 _CFStringCreateWithFormatAndArgumentsAux2 + 152
4  Foundation                     0x1af2f63c4 +[NSString stringWithFormat:] + 72
5  UIKitCore                      0x1b30d95d8 -[_UIBackgroundTaskInfo description] + 144
6  UIKitCore                      0x1b30e302c _fireBackgroundExpirationHandlers + 1068
7  UIKitCore                      0x1b30e2b2c -[UIApplication workspaceNoteAssertionExpirationImminent:] + 136
8  FrontBoardServices             0x1b41adc50 __45-[FBSUIApplicationWorkspaceShim setDelegate:]_block_invoke_3 + 48
9  libdispatch.dylib              0x1aed01524 _dispatch_client_callout + 16
10 libdispatch.dylib              0x1aecaa434 _dispatch_block_invoke_direct$VARIANT$mp + 224
11 FrontBoardServices             0x1b41fe440 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 40
12 FrontBoardServices             0x1b41fe10c -[FBSSerialQueue _queue_performNextIfPossible] + 404
13 FrontBoardServices             0x1b41fe634 -[FBSSerialQueue _performNextFromRunLoopSource] + 28
14 CoreFoundation                 0x1aefb9b64 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
15 CoreFoundation                 0x1aefb9abc __CFRunLoopDoSource0 + 80
16 CoreFoundation                 0x1aefb9244 __CFRunLoopDoSources0 + 184
17 CoreFoundation                 0x1aefb4274 __CFRunLoopRun + 788
18 CoreFoundation                 0x1aefb3c34 CFRunLoopRunSpecific + 424
19 GraphicsServices               0x1b90fd38c GSEventRunModal + 160
20 UIKitCore                      0x1b30e622c UIApplicationMain + 1932
21 MagicBox Learning              0x104644058 main + 14 (main.m:14)
22 libdyld.dylib                  0x1aee3b800 start + 4



This is what I am doing in beginBackgroundTask(expirationHandler:). Please correct what wrong I am doing here.


- (void)applicationDidEnterBackground:(UIApplication *)application {

    self.isAppLaunched      =   NO;

    _bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
        // Clean up any unfinished task business by marking where you
        // stopped or ending the task outright.

        [self cancelAllProductDownloadsInProgress];

        dispatch_async(_MAGICBOX.databaseQueue, ^{
            [application endBackgroundTask:self.bgTask];
            self.bgTask = UIBackgroundTaskInvalid;
        });
    }];

    //Dismiss keyboard
    [self.window endEditing:YES];
}

Uticas answered 30/5, 2020 at 21:46 Comment(1)
Look to see if you are calling stringWithFormat anywhere in the code that might be related.Preussen
F
3

The key line is workspaceNoteAssertionExpirationImminent. You are asking for a background task (probably with beginBackgroundTask(expirationHandler:)), and when it expires you are failing to do the correct cleanup. Therefore your app is punished by being killed dead.

Fa answered 30/5, 2020 at 22:35 Comment(8)
But that is coming in iOS 13 only, not a single instance reported in previous versions. Also, how do I do the proper cleanup?Uticas
#10320143Fa
Thanks for the answer @matt, but I am still confused why this is only coming in iOS 13 versions. Whereas the same is not crashing on versions lower than iOS 13.Uticas
Now that you have shown your implementation, it confirms that, as I told you, your implementation is completely wrong. I should see two calls to application endBackgroundTask, one for when you succeed in accomplishing your tasks, and one for when you run out of time. The link I gave you in my previous comment will tell you the correct structure for a background task. Use that structure and no other.Fa
As for why this is not giving you trouble on version before iOS 13... That's not really any concern of mine (or yours) but one reason might be that before iOS 13 you get more time to complete your background task, so your time isn't expiring.Fa
I am not initiating any network operation in beginBackgroundTask(expirationHandler:). I am just cancelling the download tasks and doing DB operations which are going on in beginBackgroundTask(expirationHandler:). Do I need to move that operation out from applicationDidEnterBackground?Uticas
For every download/upload/data task, do I need to wrap the task in background task to avoid the crash? If yes, then I have to wrap the DB operations as well under the background task?Uticas
Did you look at the answers in the link? I think you have a completely false mental idea of how to structure this call.Fa

© 2022 - 2024 — McMap. All rights reserved.