从iOS 7开始,苹果的多任务API允许应用程序在三种新的后台模式下运行:后台获取、远程通知内容和后台传输服务。苹果还允许iOS用户控制是否允许所有应用程序在后台运行,或者是否允许单个应用程序在后台运行(设置>常规>后台应用程序刷新)。有没有办法让我的应用程序以编程方式检测用户是否禁用了我的应用程序在后台刷新的能力?
发布于 2013-10-02 21:44:29
这就是你要找的。
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.");
}发布于 2017-02-10 10:53:33
针对Swift 3和iOS10进行了更新:
switch UIApplication.shared.backgroundRefreshStatus {
case .available:
print("Refresh available")
case .denied:
print("Refresh denied")
case .restricted:
print("Refresh restricted")
}发布于 2013-09-27 21:02:19
检查‘s应用程序的backgroundRefreshStatus属性。以下内容摘自苹果公司的文档。
此属性反映应用程序是否可以启动到后台以处理后台行为,例如处理后台位置更新和执行后台获取。如果您的应用程序依赖于在后台启动以执行任务,则可以使用此属性的值来确定是否可以执行此操作,并在不可行时警告用户。如果此属性的值设置为UIBackgroundRefreshStatusRestricted,则不警告用户;受限用户无法为应用程序启用多任务处理。
https://stackoverflow.com/questions/18520787
复制相似问题