From 8b32ae3da6c2dd696f0ef09456d84cd9222285ac Mon Sep 17 00:00:00 2001 From: Debjeet Biswas Date: Wed, 22 Jan 2025 14:31:40 +0530 Subject: [PATCH] chore(backend): add lifecycle app type for ios (#1767) - add new `terminated` type for `lifecycle_app.type` for iOS - document `terminated` type for `lifecycle_app.type` fixes #1754 --------- Signed-off-by: detj --- backend/api/event/event.go | 36 ++++++++++++++++++++++++++++-------- docs/api/sdk/README.md | 4 ++-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/backend/api/event/event.go b/backend/api/event/event.go index e962dcdaf..ba1c962e6 100644 --- a/backend/api/event/event.go +++ b/backend/api/event/event.go @@ -130,6 +130,9 @@ const LifecycleSwiftUITypeOnDisappear = "on_disappear" const LifecycleAppTypeBackground = "background" const LifecycleAppTypeForeground = "foreground" +// LifecycleAppTypeTerminated is used only for iOS +const LifecycleAppTypeTerminated = "terminated" + // NominalColdLaunchThreshold defines the upper bound // of a nominal cold launch duration. const NominalColdLaunchThreshold = 30 * time.Second @@ -188,13 +191,6 @@ var ValidLifecycleFragmentTypes = []string{ LifecycleFragmentTypeDetached, } -// ValidLifecycleAppTypes defines allowed -// `lifecycle_app.type` values. -var ValidLifecycleAppTypes = []string{ - LifecycleAppTypeBackground, - LifecycleAppTypeForeground, -} - // ValidLifecycleViewControllerTypes defines allowed // `lifecycle_view_controller.type` values. var ValidLifecycleViewControllerTypes = []string{ @@ -237,6 +233,27 @@ var ValidNetworkGenerations = []string{ NetworkGenerationUnknown, } +// getValidLifecycleAppTypes defines valid +// `lifecycle_app.type` values according +// to the platform. +func getValidLifecycleAppTypes(p string) (types []string) { + switch p { + case platform.Android: + types = []string{ + LifecycleAppTypeBackground, + LifecycleAppTypeForeground, + } + case platform.IOS: + types = []string{ + LifecycleAppTypeBackground, + LifecycleAppTypeForeground, + LifecycleAppTypeTerminated, + } + } + + return types +} + // makeTitle appends the message to the type // if message is present. func makeTitle(t, m string) (typeMessage string) { @@ -980,7 +997,10 @@ func (e *EventField) Validate() error { if len(e.LifecycleApp.Type) > maxLifecycleAppTypeChars { return fmt.Errorf(`%q exceeds maximum allowed characters of (%d)`, `lifecycle_app.type`, maxLifecycleAppTypeChars) } - if !slices.Contains(ValidLifecycleAppTypes, e.LifecycleApp.Type) { + + validTypes := getValidLifecycleAppTypes(e.Attribute.Platform) + + if !slices.Contains(validTypes, e.LifecycleApp.Type) { return fmt.Errorf(`%q contains invalid lifecycle app type`, `lifecycle_app.type`) } } diff --git a/docs/api/sdk/README.md b/docs/api/sdk/README.md index 2de34d32b..10c14b703 100644 --- a/docs/api/sdk/README.md +++ b/docs/api/sdk/README.md @@ -665,11 +665,11 @@ Use the `lifecycle_swift_ui` type for iOS SwiftUI view lifecycle events. #### **`lifecycle_app`** -Use the `lifecycle_app` type for Android's app lifecycle events. +Use the `lifecycle_app` type for app's lifecycle events. | Field | Type | Optional | Comment | | ------ | ------ | -------- | ------------------------------------------------------------- | -| `type` | string | No | One of the following:
- `background`
- `foreground`
- `terminated` | +| `type` | string | No | One of the following:
- `background`
- `foreground`
- `terminated`. `terminated` option is only supported on iOS. | #### **`cold_launch`**