后台获取在大约10到14个小时后停止工作 [英] Background fetch stops working after about 10 to 14 hours

查看:82
本文介绍了后台获取在大约10到14个小时后停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序每隔30分钟使用背景提取来发送和上传一小部分数据.在最小化应用程序的使用前,该服务正常工作约10-14小时-应用程序每30分钟正确发送和接收一次数据.

My application uses a backgroud fetch to send and upload a small portion of data every 30 minutes. The service is working correctly for about 10 - 14 hours after the application is minimized from working in the foregroud - the application is correctly sending and receiving the data every 30 minutes.

有人几个小时后知道服务会如何吗? iOS系统是否会自动终止应用程序,因此后台获取会停止工作?

Does anyone know what happens with the service after couple of hours? Does the iOS system automatically terminate the application and therefore the background fetch stops working?

有人可以解释吗?

推荐答案

iOS提供了30秒的时间范围,以便唤醒应用程序,获取新数据,更新其界面,然后再次进入睡眠状态.您有责任确保在30秒钟内完成所有已执行的任务,否则系统会突然停止它们.

iOS provides a 30 seconds time frame in order the app to be woken up, fetch new data, update its interface and then go back to sleep again. It is your duty to make sure that any performed tasks will manage to get finished within these 30 seconds, otherwise the system will suddenly stop them.

可能是由于互联网速度太慢,导致您的应用花费了30秒以上的时间;系统停止了您的应用程序.

maybe the internet was slow that your app took more than 30 seconds & system stopped your application.

-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{

    NSDate *fetchStart = [NSDate date];

  // Make your process here

    [viewController fetchNewDataWithCompletionHandler:^(UIBackgroundFetchResult result) {
        completionHandler(result);

        NSDate *fetchEnd = [NSDate date];
        NSTimeInterval timeElapsed = [fetchEnd timeIntervalSinceDate:fetchStart];
        NSLog(@"Background Fetch Duration: %f seconds", timeElapsed);

    }];
}

Apple还提供了一种算法,可根据您自己对应用程序的使用情况来定义后台获取应该触发的频率.如果您经常使用它,那么它将尽可能频繁地获取数据,但是如果每天使用,例如下午4点,则后台获取操作应该在之前触发,因此在启动数据时会对其进行更新.

Also Apple provides an algorithm which defines how often the background fetch should trigger, based on your own usage of the app. If you use it a lot, then it will fetch as often as possible, but if you use like at 4pm every day, the background fetch should trigger just before, so your data is updated when you launch it.

这篇关于后台获取在大约10到14个小时后停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆