Skip to content

Commit

Permalink
fix(iOS): Fixing task repeat mechanism for iOS (#108)
Browse files Browse the repository at this point in the history
* Default config repeat property to false

* Reschedule iOS task if configured to repeat

* Adding changeset

---------

Co-authored-by: Joseph Pender <[email protected]>
  • Loading branch information
NextNebula and theproducer authored Oct 7, 2024
1 parent 4cc44dd commit 4957271
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-vans-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@capacitor/background-runner": minor
---

(iOS) Fixing task repeat functionality
4 changes: 4 additions & 0 deletions packages/capacitor-plugin/ios/Plugin/BackgroundRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public class BackgroundRunner {
_ = try BackgroundRunner.shared.execute(config: config)

task.setTaskCompleted(success: true)

if config.repeats {
try self.scheduleBackgroundTasks()
}
} catch {
print("background task error: \(error)")
task.setTaskCompleted(success: false)
Expand Down
4 changes: 2 additions & 2 deletions packages/capacitor-plugin/ios/Plugin/RunnerConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public struct RunnerConfig {
let src: String
var autoSchedule: Bool
var event: String
let repeats: Bool?
let repeats: Bool
let enableWatchConnectivity: Bool

let interval: Int?
Expand All @@ -28,7 +28,7 @@ public struct RunnerConfig {
self.label = label
self.src = src
self.event = event
self.repeats = repeats
self.repeats = repeats ?? false
self.interval = interval
self.autoSchedule = autoStart ?? false
self.enableWatchConnectivity = jsObject["enableWatchConnectivity"] as? Bool ?? false
Expand Down

0 comments on commit 4957271

Please sign in to comment.