当我的应用程序从 iOS 后台恢复时,我遇到以下问题: 如果互联网连接是 3G 或 WIFI,一切正常。如果没有数据连接(也没有 Wifi,也没有移动设备),一切都很好。
但是:如果移动连接不好但 Ti.Network.online 仍然返回 true,或者如果有 WIFI 连接但无法访问互联网,则应用程序在恢复后“挂起”并最终崩溃。在设备日志中,我得到“未能及时恢复”。即使我从未添加“恢复”事件侦听器,也会发生这种情况。
请就此向我提出建议。
这是代码: -
self.expirationHandler =
^{
[app endBackgroundTask:self.bgTask];
self.bgTask = UIBackgroundTaskInvalid;
self.bgTask = [app beginBackgroundTaskWithExpirationHandler:self.expirationHandler];
DLog(@"Expired");
self.jobExpired = YES;
while(self.jobExpired)
{
DLog(@"Spin the While loop to run the app in infinite");
}
// Restart the background task so we can run forever.
[self runtheApp:nil];
};
self.bgTask = [app beginBackgroundTaskWithExpirationHandler:expirationHandler];
[self startLoggerInBackground];
}