Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Implement Plugin for Background Tasks #3045

Closed
1 of 4 tasks
nicobytes opened this issue Jun 3, 2020 · 4 comments
Closed
1 of 4 tasks

bug: Implement Plugin for Background Tasks #3045

nicobytes opened this issue Jun 3, 2020 · 4 comments

Comments

@nicobytes
Copy link

nicobytes commented Jun 3, 2020

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
  • 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

@jcesarmobile
Copy link
Member

it's not a bug, you already requested this 2 days ago
#3032

@nicobytes
Copy link
Author

nicobytes commented Jun 3, 2020

@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

@jcesarmobile
Copy link
Member

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.

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 11, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants