Capacitor: bug: Implement Plugin for Background Tasks

Created on 3 Jun 2020  路  3Comments  路  Source: ionic-team/capacitor

Bug Report

Capacitor Version

npx cap doctor output:

@capacitor/cli 2.1.2
@capacitor/core 2.1.2
@capacitor/ios 2.1.2

Affected Platform(s)

  • [ ] Android
  • [x] iOS
  • [ ] Electron
  • [ ] Web

Current Behavior

In IOS 13 there is BGTaskScheduler for run tasks in background mode

https://developer.apple.com/documentation/backgroundtasks/bgtaskscheduler

I must register all of the tasks before the end of the app launch sequence. The place to register that tasks are in AppDelegate with its handler.

Like this:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    BGTaskScheduler.shared.register(
        forTaskWithIdentifier:"com.nicobytes.timer",
        using: nil
    )
    {task in
        self.handleTimerTask(task: task as! BGAppRefreshTask)
    }
    return true
  }

func handleTimerTask(task: BGAppRefreshTask) {
      print("Handling task")
      task.expirationHandler = {
        task.setTaskCompleted(success: false)
      }

      task.setTaskCompleted(success: true)

       CAPBridge.triggerWindowJSEvent("taskCompleted", true) <--- Error here
    }

But in Capacitor API don't allow use de Bridge for communique events from AppDelegate using CAPBridge

All 3 comments

it's not a bug, you already requested this 2 days ago
https://github.com/ionic-team/capacitor/issues/3032

@jcesarmobile mmm sorry, but I tried create my own plugin to solve my problem but Capacitor API doesn't allow communique correctly with IOS API in this case.

I consider this a bug and don't allow create plugins for capacitor ecosystem.

Please check, I love capacitor and I understand this feature is not a priority for us, is the reason for I tried create my own plugin but the Capacitor API don't allow communique.

Is important for our app, with enterprise support ($$) Is possible support for that?

cc @mlynch

If you need to put code in the didFinishLaunchingWithOptions you'll have to document that on the plugin (for users) or put it in your app if the plugin is just for you. It's not supported because the AppDelegate.swift belongs to the user app and Capacitor doesn't do changes on the user app, but encourages users to do any needed changes there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moberwasserlechner picture moberwasserlechner  路  3Comments

ebk46 picture ebk46  路  3Comments

MatanYadaev picture MatanYadaev  路  3Comments

daniel-lucas-silva picture daniel-lucas-silva  路  3Comments

alexcroox picture alexcroox  路  3Comments