Push to start live activities default LA#1416
Merged
brismithers merged 5 commits intopush-to-start-live-activitiesfrom May 6, 2024
Merged
Push to start live activities default LA#1416brismithers merged 5 commits intopush-to-start-live-activitiesfrom
brismithers merged 5 commits intopush-to-start-live-activitiesfrom
Conversation
…s. The primary use is for cross-platform apps to more easily drive the setup and creation of a live activity. Rather than have to create their own cross-platform<->iOS bridge, they can use the OneSignal SDK to handle it.
nan-li
approved these changes
May 3, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
Add a "Default" Live Activity Attribute model for easy setup of a Live Activity.
Details
This adds to the push-to-start Live Activity work the concept of a "Default" Live Activity. The following new external interfaces are provided for customer app's to use:
DefaultLiveActivityAttributesstruct which conforms toOneSignalLiveActivityAttributes(i.e. a OneSignal awareActivityAttributes). A customer app can create a widget withActivityConfiguration(for: DefaultLiveActivityAttributes.self)to use this provided model. TheDefaultLiveActivityAttributesestablishes a dynamic dictionary of attributes, able to consume any customer-provided structure of data.OneSignal.LiveActivities.setupDefault()which tells the OneSignal SDK to manage the LiveActivity lifecycle for any live activity based on theOneSignalLiveActivityAttributestype. When calling this method, a customer can use both 'push-to-start' andpush-to-updatenotifications to start/update/end their Live Activity.OneSignal.LiveActivities.startDefault(activityId, activityAttributes, initialContentState)which allows a customer app to start a live activity based on theOneSignalLiveActivityAttributestype "in app", rather than via "push-to-start" notification.The default Live Activity is aimed to reduce the complexity cross-platform apps have to deal with when using Live Activities. Prior to this change cross platform apps would have to define their own
ActivityAttributesand manage the LA lifecycle through their own cross-platform<->iOS native binding. With this change, the OneSignal SDK owns theActivityAttributesstruct and can therefore manage the entire LA lifecycle on the customer app's behalf.The downside to using a default Live Activity is:
ActivityAttributes. For example, instead of rendering a text attribute asText(context.state.message)it must be rendered asText(context.state.data["message"]?.asString() ?? "").Other Changes
OneSignalLiveActivityAttributesprotocol to enforce its ContentState conforms toOneSignalLiveActivityContentState. The newOneSignalLiveActivityContentStaterequires the definition of an optionalonesignalattribute of typeOneSignalLiveActivityContentStateData. This will be used in the future by OneSignal to communicate between the OneSignal and OneSignal SDK for each push-to-update notification.Motivation
Live Activities ease of use
Scope
Live Activities
Testing
Unit testing
setupDefault()andstartDefaultto ensure no regression in the public API will occur.DefaultLiveActivityAttributeswere added to ensure the various structures of data can be successfully decoded and used by a customer app's widget.Manual testing
Using the example app I ensured the default live activity could be started via push-to-start and via in-app with varying structures of data.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is