【问题标题】:Detecting user settings for Background App Refresh in iOS 7在 iOS 7 中检测后台应用刷新的用户设置
【发布时间】:2013-09-02 11:13:42
【问题描述】:

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

【问题讨论】:

  • Apple 关于家长控制的页面,包括启用/禁用限制,特别是后台应用刷新:support.apple.com/en-us/HT201304。很高兴有一个指南而不是在 iPhone 设置迷宫中徘徊。

标签: objective-c background multitasking ios7 settings


【解决方案1】:

检查 UIApplication 的 backgroundRefreshStatus 属性。以下内容引用自苹果文档。

该属性反映应用是否可以启动到后台来处理后台行为,例如处理后台位置更新和执行后台获取。如果您的应用程序依赖于在后台启动来执行任务,您可以使用此属性的值来确定是否可以这样做,如果不可以,则警告用户。如果此属性的值设置为 UIBackgroundRefreshStatusRestricted,则不警告用户;受限用户无法为应用启用多任务处理。

【讨论】:

    【解决方案2】:

    这就是你要找的。​​p>

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

    【讨论】:

    • 谢谢,很有用。但是,您能否评论一下我在这方面的依赖问题 - stackoverflow.com/questions/19235183/…
    • 嗨,要调用这个方法。在后台调用失败
    • 我猜后台 appRefresh 和静默通知无关吧?
    【解决方案3】:

    为 Swift 3 和 iOS10 更新:

    switch UIApplication.shared.backgroundRefreshStatus {
    case .available:
        print("Refresh available")
    case .denied:
        print("Refresh denied")
    case .restricted:
        print("Refresh restricted")
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-24
      • 2016-04-17
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多