【问题标题】:App crashes on entering background in iOS在 iOS 中进入后台时应用程序崩溃
【发布时间】:2013-04-03 08:23:13
【问题描述】:
    TESTPRO_TEST[830] has active assertions beyond permitted time: 
        {(
            <BKProcessAssertion: 0x1fd48670> identifier: UIKitBackgroundCompletionTask process: TESTPRO_TEST[830] permittedBackgroundDuration: 600.000000 reason: finishTask owner pid:830 preventSuspend  preventIdleSleep ,
            <BKProcessAssertion: 0x2083f190> identifier: UIKitBackgroundCompletionTask process: TESTPRO_TEST[830] permittedBackgroundDuration: 600.000000 reason: finishTask owner pid:830 preventSuspend  preventIdleSleep 
        )}
   <Warning>: Forcing crash report of DSC_TEST[830]...
   <Warning>: Finished crash reporting.
     [830] has active assertions beyond permitted time: 
        {(
            <BKProcessAssertion: 0x1fd48670> identifier: UIKitBackgroundCompletionTask process: [830] permittedBackgroundDuration: 600.000000 reason: finishTask owner pid:830 preventSuspend  preventIdleSleep 
        )}
   <Warning>: Forcing crash report of [830]...
   <Error>: Multiple simulate crash requests for pid 830
   <Warning>: Finished crash reporting.
   <Warning>: pid_suspend failed for [830]: Unknown error: -1, Unknown error: -1
    com.apple.launchd[1] (UIKitApplication:com.testPro.Test[0x4aff][830]) <Notice>: (UIKitApplication:com.testPro.Test[0x4aff]) Exited: Killed: 9
   <Warning>: Application 'UIKitApplication:com.testPro.Test[0x4aff]' exited abnormally with signal 9: Killed: 9
   �<Debug>: launchd[869] Builtin profile: container (sandbox)
   <Debug>: launchd[869] Container: /private/var/mobile/Applications/3CF1EEC9-B6EF-45EA-999D-EBB9C02106EE (sandbox)
   <Error>: Not saving crash log because we have reached the limit for logs to store on disk.  Sync or otherwise clear logs from /var/mobile/Library/Logs/CrashReporter to save new logs.
   <Error>: Could not save crash report to disk!

当应用程序进入后台时,我已经添加了代码

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

    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    UIBackgroundTaskIdentifier bgTask = 0;
    UIApplication *app = [UIApplication sharedApplication];
    bgTask = [app beginBackgroundTaskWithExpirationHandler: ^{
        [app endBackgroundTask:bgTask];
    }];

}

当应用程序进入后台时发生崩溃。谁能帮我解决这个崩溃?

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    原因很明显 - 它在日志中指出 - 你的时间已经过期。 Applications running background tasks have a finite amount of time in which to run them. (You can find out how much time is available using the backgroundTimeRemaining property.) If you do not call endBackgroundTask: for each task before time expires, the system kills the application.

    我认为您不应该在applicationDidEnterBackground: 中调用此方法,尝试将其移动到适当的位置(您开始工作的地方)。您可以使用它来包装可能在 bkg 中也可以工作的长时间播放进程。不要严重评判我的回答,这只是我的猜测,可能会成真。

    附:这是What are beginBackgroundTaskWithExpirationHandler and endBackgroundTask methods的很好解释

    【讨论】:

    • 感谢您的回复。但是在后台运行的应用程序的有限时间是多少?
    • 这是一些苹果常数,但问题是你以错误的方式使用了这个方法!您不应该在applicationDidEnterBackground 中调用它,最好在开始某些任务之前调用它,并且不要忘记在最后调用endBackgroundTask。这是一个很好的解释实际上是什么beginBackgroundTaskWithExpirationHandlerstackoverflow.com/questions/12071726/…
    • 在 iOS7 中,普通应用程序在后台的有限时间是 3 分钟,即 180 秒,而在 iOS7 之前,它是 10 分钟,即 600 秒。
    猜你喜欢
    • 2014-05-09
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多