Skip to content

Commit

Permalink
[GH-418] Replace helper block with function (#3283)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlepinski authored and crow committed Nov 26, 2024
1 parent 89c20c1 commit 5cd165b
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions Airship/AirshipCore/Source/LiveActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,27 +199,27 @@ fileprivate class AirshipBackgroundTask {
@available(iOS 16.1, *)
extension Activity where Attributes : ActivityAttributes {

fileprivate class func _airshipCheckActivities(activityBlock: @escaping @Sendable (Activity<Attributes>) -> Void) {
self.activities.filter { activity in
if #available(iOS 16.2, *) {
return activity.activityState == .active || activity.activityState == .stale
} else {
return activity.activityState == .active
}
}.forEach { activity in
activityBlock(activity)
}
}

/// Calls `checkActivity` on every active activity on the first call and on each `pushToStartTokenUpdates` update.
/// - Parameters:
/// - activityBlock: Block that is called with the activity
public class func airshipWatchActivities(activityBlock: @escaping @Sendable (Activity<Attributes>) -> Void) {
let checkHelper: @Sendable () -> Void = {
self.activities.filter { activity in
if #available(iOS 16.2, *) {
return activity.activityState == .active || activity.activityState == .stale
} else {
return activity.activityState == .active
}
}.forEach { activity in
activityBlock(activity)
}
}

Task {
checkHelper()
_airshipCheckActivities(activityBlock: activityBlock)
if #available(iOS 17.2, *) {
for await _ in Activity<Attributes>.pushToStartTokenUpdates {
checkHelper()
_airshipCheckActivities(activityBlock: activityBlock)
}
}
}
Expand Down

0 comments on commit 5cd165b

Please sign in to comment.