如何检查iOS上是否启用了BackgroundFetching?

时间:2013-11-01 20:13:23

标签: background ios7

我想确定用户是否在“偏好设置”应用中关闭了“后台提取”功能。如果他将其关闭,我的应用程序将无效。

1 个答案:

答案 0 :(得分:6)

以下是执行此操作的代码:

if ([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusAvailable) {

    NSLog(@"Background fetch is available for the app.");
}else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusDenied)
{
    NSLog(@"Background fetch for this app or for the whole system is disabled.");
}else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusRestricted)
{
    NSLog(@"Background updates are unavailable and the user cannot enable them again. For example, this status can occur when parental controls are in effect for the current user.");
}