OneSignal-iOS-SDK
OneSignal-iOS-SDK copied to clipboard
Push to start live activities default LA
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:
- A
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. - A new function
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. - A new function
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 ActivityAttributes and manage the LA lifecycle through their own cross-platform<->iOS native binding. With this change, the OneSignal SDK owns the ActivityAttributes struct and can therefore manage the entire LA lifecycle on the customer app's behalf.
The downside to using a default Live Activity is:
- The app will be limited to only one Live Activity type.
- The widget rendering logic is slightly more complicated in that it is using a dynamically defined
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
- Updated
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
- Additional unit tests were added to cover the new functions
setupDefault()andstartDefaultto ensure no regression in the public API will occur. - Additional unit tests around the decoding of
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
- [ ] Notifications
- [ ] Display
- [ ] Open
- [ ] Push Processing
- [ ] Confirm Deliveries
- [ ] Outcomes
- [ ] Sessions
- [ ] In-App Messaging
- [ ] REST API requests
- [ ] Public API changes
- [x] Live Activities
Checklist
Overview
- [x] I have filled out all REQUIRED sections above
- [ ] PR does one thing
- If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
- [x] Any Public API changes are explained in the PR details and conform to existing APIs
Testing
- [x] I have included test coverage for these changes, or explained why they are not needed
- [x] All automated tests pass, or I explained why that is not possible
- [x] I have personally tested this on my device, or explained why that is not possible
Final pass
- [x] Code is as readable as possible.
- Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
- [x] I have reviewed this PR myself, ensuring it meets each checklist item
- WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.