Skip to content

Commit 72ae337

Browse files
committed
Add receive receipts handling
* Listen for `contentUpdates` as a way to know the live activity has been updated via a notification or "in app". This asynchronous sequence is triggered for all PTS, PTU, and live activities that are started and updated "in app". * We will check for notification ID to know if this change was generated from a notification and track the receive receipt.
1 parent 01ff92f commit 72ae337

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

iOS_SDK/OneSignalSDK/OneSignalLiveActivities/Source/OneSignalLiveActivitiesManagerImpl.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ public class OneSignalLiveActivitiesManagerImpl: NSObject, OSLiveActivities {
202202
for activity in Activity<Attributes>.activities {
203203
listenForActivityStateUpdates(activityType, activity: activity, options: options)
204204
listenForActivityPushToUpdate(activityType, activity: activity, options: options)
205+
if #available(iOS 16.2, *) {
206+
listenForContentUpdates(activityType, activity: activity)
207+
}
205208
}
206209

207210
// Establish listeners for activity updates
@@ -221,6 +224,9 @@ public class OneSignalLiveActivitiesManagerImpl: NSObject, OSLiveActivities {
221224

222225
listenForActivityStateUpdates(activityType, activity: activity, options: options)
223226
listenForActivityPushToUpdate(activityType, activity: activity, options: options)
227+
if #available(iOS 16.2, *) {
228+
listenForContentUpdates(activityType, activity: activity)
229+
}
224230
}
225231
}
226232
}
@@ -272,5 +278,23 @@ public class OneSignalLiveActivitiesManagerImpl: NSObject, OSLiveActivities {
272278
}
273279
}
274280
}
281+
282+
@available(iOS 16.2, *)
283+
private static func listenForContentUpdates<Attributes: OneSignalLiveActivityAttributes>(_ activityType: Attributes.Type, activity: Activity<Attributes>) {
284+
Task {
285+
for await content in activity.contentUpdates {
286+
// Don't track a live activity started / updated "in app" without a notification
287+
if let notificationId = activity.content.state.onesignal?.notificationId {
288+
OneSignalLiveActivitiesManagerImpl.addReceiveReceipts(notificationId: notificationId, activityType: "\(activityType)", activityId: activity.attributes.onesignal.activityId)
289+
}
290+
}
291+
}
292+
}
293+
294+
private static func addReceiveReceipts(notificationId: String, activityType: String, activityId: String) {
295+
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignal.LiveActivities addReceiveReceipts called with notificationId: \(notificationId), activityType: \(activityType), activityId: \(activityId)")
296+
let req = OSRequestLiveActivityReceiveReceipts(key: notificationId, activityType: activityType, activityId: activityId)
297+
_executor.append(req)
298+
}
275299
}
276300
#endif

0 commit comments

Comments
 (0)