我们最近开始在应用程序切换到后台或终止时从TestFlight获取应用程序崩溃消息,当我们查看崩溃日志时,发现这是我们的应用程序花费了比规定的5秒更长的时间。因此,我们添加了扩展后台执行任务:
- (void)extendBackgroundExecutionTime
{
// ** Extend execution for a maximum of 15 seconds **
if ( backgroundTimeExtensionActive )
return;
NSLog( @"SCAD: >>>- Kick off background extension task" );
backgroundUpdateTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask:backgroundUpdateTask];
}];
backgroundTimeExtensionActive = YES;
[NSTimer scheduledTimerWithTimeInterval:15.0 repeats:NO block:^(NSTimer * _Nonnull timer) {
NSLog( @"SCAD: >>>- Controlled ending" );
[[UIApplication sharedApplication] endBackgroundTask:backgroundUpdateTask];
}];
}
当应用程序发送到后台时,以上操作正常(我们的应用程序大约需要9秒钟才能完成),但是当应用程序终止时,它会被忽略,而我仍然会遇到TestFlight崩溃错误。我需要确保能够“安全”终止的主要原因是确保将任何脏配置写入手机,并且能够将位置精度从“高”更改为“重要”。
任何帮助将不胜感激。