Detecting user settings for Background App Refresh in iOS 7
Asked Answered
I

3

46

Starting with iOS 7, Apple's Multitasking APIs allow apps to run in three new Background Modes: Background fetch, Remote notification content, and Background transfer service. Apple also gives iOS users the ability to control whether all apps are allowed to run in the background or whether individual apps can run in the background (Settings > General > Background App Refresh). Is there is a way for my app to programmatically detect whether the user has disabled my app's ability to refresh in the background?

Intelsat answered 29/8, 2013 at 20:55 Comment(1)
Apple's page on parental controls, which includes enabling/disabling Restrictions, and specifically Background App Refresh: support.apple.com/en-us/HT201304. Nice to have a guide vs. wandering through the iPhone settings maze.Milinda
P
81

this is what you are looking for.

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

    NSLog(@"Background updates are available for the app.");
}else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusDenied)
{
    NSLog(@"The user explicitly disabled background behavior for this app or for the whole system.");
}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.");
}
Popedom answered 2/10, 2013 at 13:44 Comment(3)
Thanks, it was useful. However, can you comment on my dependent question in this regard - #19235683Jailer
Hi,were to call thiS method .In background its fails to callProletarian
I'm guessing background appRefresh has nothing to do with Silent notifications is that right?Idolla
B
9

Updated for Swift 3 and iOS10:

switch UIApplication.shared.backgroundRefreshStatus {
case .available:
    print("Refresh available")
case .denied:
    print("Refresh denied")
case .restricted:
    print("Refresh restricted")
}
Berkly answered 10/2, 2017 at 2:53 Comment(0)
E
8

Check UIApplication's backgroundRefreshStatus property. The following is quoted from apple document.

This property reflects whether the app can be launched into the background to handle background behaviors, such as processing background location updates and performing background fetches. If your app relies on being launched into the background to perform tasks, you can use the value of this property to determine if doing so is possible and to warn the user if it is not. Do not warn the user if the value of this property is set to UIBackgroundRefreshStatusRestricted; a restricted user does not have the ability to enable multitasking for the app.

Exuberate answered 27/9, 2013 at 13:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.