我正在编写一个依赖于位置跟踪并向服务器发送有关位置的数据的应用程序。然而,问题在于它必须24/7运行,目前我正在经历每2-3天发生一次的随机崩溃。为了使应用程序在后台持续运行,我在applicationDidEnterBackground方法中使用beginBackgroundTaskWithExpirationHandler方法放置了一个NSTimer。计时器每分钟执行一次,并停止/启动位置服务。
这是一个示例崩溃日志Here is a sample crash log 代码基本上看起来像这样:
我正在使用 GCDAsyncSockets 进行连接,每个调用都有大约 30 秒的超时时间。
我真的没有想法,是什么原因导致崩溃发生?
这是一个示例崩溃日志Here is a sample crash log 代码基本上看起来像这样:
UIApplication *app = [UIApplication sharedApplication];
__block UIBackgroundTaskIdentifier bgTaskId = 0;
bgTaskId = [app beginBackgroundTaskWithExpirationHandler:^{
NSTimer *t = [NSTimer scheduledTimerWithTimeInterval: 1 * 60.0 target: self selector: @selector(onTick) userInfo: nil repeats: YES];
[t fire];
if (bgTaskId != UIBackgroundTaskInvalid){
[app endBackgroundTask: bgTaskId];
bgTaskId = UIBackgroundTaskInvalid;
}
}];
我正在使用 GCDAsyncSockets 进行连接,每个调用都有大约 30 秒的超时时间。
我真的没有想法,是什么原因导致崩溃发生?