Jenny Jose Jenny Jose - 3 months ago 49
Objective-C Question

App crashes while app is going into background and when iPad gets auto-locked

I am facing a weird issue in my application when my app goes into Background mode and when iPad gets locked. Till then its working fine but while I am unlocking the device and opening the app from background, its crashing.

This is the Crash log, I am getting from device

Exception Type: 00000020
Exception Codes: 0x000000008badf00d
Exception Note: SIMULATED (this is NOT a crash)
Highlighted by Thread: 8

Application Specific Information:
<BKNewProcess: 0x12cd18cb0; com.apps-factory; pid: 540; hostpid: -1> has active assertions beyond permitted time:
{(
<BKProcessAssertion: 0x12cd1e3b0> id: 540-72C6AF6C-F674-40E8-BA89-EFE4BF52F8D6 name: Called by UIKit, from <redacted> process: <BKNewProcess: 0x12cd18cb0; com.apps-factory; pid: 540; hostpid: -1> permittedBackgroundDuration: 180.000000 reason: finishTask owner pid:540 preventSuspend preventIdleSleep preventSuspendOnSleep
)}

Elapsed total CPU time (seconds): 82.430 (user 82.430, system 0.000), 23% CPU
Elapsed application CPU time (seconds): 77.475, 21% CPU

Filtered syslog:
None found


My app has continuous dot animation on screen like rainfall effect based on data from DB which is being synced with Server.

Any help will be highly appreciated.
Thanks in advance!!

Answer

As looking into your crash log i am sure that reason behind your crash is due to background fetch still in process after 3 mins (180 seconds).

so if i am not wrong after 3 mins it will kill your app and while you reopen it its already in crash mode so will not run directly.

I am facing same issue in my app so to resolve this issue i have begin background task in my code through AppDelegate like this:

[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];

and than we need to end that task in Application delegate method

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

    __block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
                [application endBackgroundTask:bgTask];
                bgTask = UIBackgroundTaskInvalid;
        //Save your state or data while invalidating bgTask.

        }];
}

and thats why in your crash report apple clearly mention that OS only allow any task in background for 3 mins only!

check your crash

Application Specific Information:
    <BKNewProcess: 0x12cd18cb0; com.apps-factory; pid: 540; hostpid: -1> has active assertions beyond permitted time: 
    {(
        <BKProcessAssertion: 0x12cd1e3b0> id: 540-72C6AF6C-F674-40E8-BA89-EFE4BF52F8D6 name: Called by UIKit, from <redacted> process:  <BKNewProcess: 0x12cd18cb0; com.apps-factory; pid: 540; hostpid: -1>  permittedBackgroundDuration: 180.000000  reason: finishTask owner  pid:540 preventSuspend  preventIdleSleep  preventSuspendOnSleep 
    )}

permittedBackgroundDuration: 180.000000 reason: finishTask owner

means we have only 180 seconds to perform any task in background as mention here in apple documentation.

if you still requires more time to execute your task so you need to enable your app background mode with specific reason otherwise apple may reject your app.

Hope this will help to resolve your crash.

Comments