ios - BGTaskScheduler 提交调用失败,BGTaskSchedulerErrorDomain 代码为 : 1

标签 ios swift backgroundtaskidentifier

BGTaskScheduler 因“BGTaskSchedulerErrorDomain”而失败 - 代码:iOS 13.0 上的 1

我已经尝试过 Apple 提供的示例程序 ColorFeed,它面临同样的问题

let request = BGProcessingTaskRequest(identifier: "com.example.apple-samplecode.ColorFeed.db_cleaning")
request.requiresNetworkConnectivity = false
request.requiresExternalPower = true

do 
{
  try BGTaskScheduler.shared.submit(request)
} catch {
  print("Could not schedule database cleaning: \(error)")
}

上面的代码在 applicationDidEnterBackground 中被调用

早些时候任务在 didFinishLaunchingWithOptions 中注册 ...

 BGTaskScheduler.shared.register(forTaskWithIdentifier: "com.example.apple-samplecode.ColorFeed.db_cleaning", using: nil) { task in

        // Downcast the parameter to a processing task as this identifier is used for a processing request.
        self.handleDatabaseCleaning(task: task as! BGProcessingTask)

 }

最佳答案

代码1表示BGTaskScheduler.Error.unavailable

根据文档:

This error usually occurs for one of three reasons:

  • The user has disabled background refresh in settings.
  • The app is running on Simulator which doesn’t support background processing.
  • The extension either hasn’t set RequestsOpenAccess to YES in The Info.plist File, or the user hasn’t granted open access.

您是在真实设备上运行吗?该设备是否启用了后台刷新?

关于ios - BGTaskScheduler 提交调用失败,BGTaskSchedulerErrorDomain 代码为 : 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58680588/

相关文章:

objective-c - 在 obj-c 中与 NSArray 一起使用的长度混淆

ios - 我的playerCard的初始化无效

ios - Xcode7 - 等高乘数约束导致约束冲突

swift - Swift 添加文本到图像不在正确的位置

ios - Swift 后台执行

swift - 后台请求不执行 Alamofire Swift

objective-c - 在一个 NSOperationQueue 上抢占 NSOperation 并将 NSOperation 放置到一个单独的 NSOperationQueue 上?

ios - Objective-C 后台任务 UIBackgroundTaskIdentifier 重复

javascript - iPhone 上的 PhoneGap 不会加载外部脚本