在 iOS 7 中检测后台应用程序刷新的用户设置 [英] Detecting user settings for Background App Refresh in iOS 7

查看:20
本文介绍了在 iOS 7 中检测后台应用程序刷新的用户设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 iOS 7 开始,Apple 的多任务 API 允许应用在三种新的后台模式下运行:后台获取、远程通知内容和后台传输服务.Apple 还让 iOS 用户能够控制是否允许所有应用程序在后台运行或单个应用程序是否可以在后台运行(设置 > 常规 > 后台应用程序刷新).有没有办法让我的应用程序以编程方式检测用户是否禁用了我的应用程序在后台刷新的能力?

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?

推荐答案

这就是您要找的.

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.");
}

这篇关于在 iOS 7 中检测后台应用程序刷新的用户设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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