### Install Go SDK Source: https://documentation.onesignal.com/docs/en/server-sdk-reference Install the Go SDK using go get. Check the package registry for the latest version. ```bash go get github.com/OneSignal/onesignal-go-api/v5 ``` -------------------------------- ### Example Initialization with Custom Code Setup Source: https://documentation.onesignal.com/docs/en/web-sdk-reference Example of initializing the OneSignal Web SDK with custom code, including configuration for the notify button and prompt options. ```javascript ``` -------------------------------- ### Setup and Start Default Live Activity Source: https://documentation.onesignal.com/docs/en/mobile-sdk-reference Configure Live Activities for push-to-start or launch them directly from the app. Ensure the activity ID is unique and does not contain '/' characters. ```csharp using OneSignalSDK; //Push To Start OneSignal.LiveActivities.SetupDefault(); //Launching the Live Activity from within the app (not needed for push to start) string activityId = "my_activity_id"; OneSignal.LiveActivities.StartDefault( activityId, new Dictionary() { { "title", "Welcome!" } }, new Dictionary() { { "message", new Dictionary() { { "en", "Hello World!"} }}, }); ``` ```javascript import { OneSignal } from 'react-native-onesignal' //Push To Start OneSignal.LiveActivities.setupDefault() //Launching the Live Activity from within the app (not needed for push to start) const activityId = "my_activity_id" const attributes = { title: "Sample Title" } ; const content = { message: { en: "message" } }; OneSignal.LiveActivities.startDefault(activityId, attributes, content); ``` ```dart import 'package:onesignal_flutter/onesignal_flutter.dart'; OneSignal.LiveActivities.setupDefault() //Launching the Live Activity from within the app (not needed for push to start) const String activityId = "my_activity_id"; OneSignal.LiveActivities.startDefault(activityId!, { "title": "Welcome!" }, { "message": {"en": "Hello World!"}, }); ``` ```javascript //Ionic import OneSignal from "onesignal-cordova-plugin"; //Push To Start OneSignal.LiveActivities.setupDefault(); //Launching the Live Activity from within the app (not needed for push to start) const activityId = "my_activity_id"; const attributes = { title: "Sample Title" }; const content = { message: { en: "message" } }; OneSignal.LiveActivities.startDefault(activityId, attributes, content); //Cordova //Push To Start window.plugins.OneSignal.LiveActivities.setupDefault(); //Launching the Live Activity from within the app (not needed for push to start) const activityId = "my_activity_id"; const attributes = { title: "Sample Title" }; const content = { message: { en: "message" } }; window.plugins.OneSignal.LiveActivities.startDefault( activityId, attributes, content ); ``` -------------------------------- ### Install C# (.NET) SDK Source: https://documentation.onesignal.com/docs/en/server-sdk-reference Install the C# (.NET) SDK using the dotnet CLI. Check the package registry for the latest version. ```bash dotnet add package OneSignalApi ``` -------------------------------- ### Install Node.js SDK Source: https://documentation.onesignal.com/docs/en/server-sdk-reference Install the Node.js SDK using npm. Check the package registry for the latest version. ```bash npm install @onesignal/node-onesignal ``` -------------------------------- ### Install Python SDK Source: https://documentation.onesignal.com/docs/en/server-sdk-reference Install the Python SDK using pip. Check the package registry for the latest version. ```bash pip install onesignal-python-api ``` -------------------------------- ### Example iOS Podfile Configuration Source: https://documentation.onesignal.com/docs/en/cordova-sdk-setup An example of a complete ios/Podfile, demonstrating how to include the OneSignal pod alongside React Native dependencies and post-install hooks. ```ruby target 'MyApp' do config = use_native_modules! use_react_native!( :path => config[:reactNativePath], # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) post_install do |installer| # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202 react_native_post_install( installer, config[:reactNativePath], :mac_catalyst_enabled => false, # :ccache_enabled => true ) end end target 'OneSignalNotificationServiceExtension' do pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0' end ``` -------------------------------- ### Install Ruby SDK Source: https://documentation.onesignal.com/docs/en/server-sdk-reference Add the Ruby SDK to your Gemfile and run bundle install. Check the package registry for the latest version. ```ruby gem 'onesignal', '~> 5.3' ``` -------------------------------- ### Install React Native OneSignal SDK Source: https://documentation.onesignal.com/docs/en/react-native-sdk-setup Run this command to install the OneSignal SDK if it cannot be found. ```bash npm install react-native-onesignal ``` -------------------------------- ### setup() - Live Activities Source: https://documentation.onesignal.com/docs/en/mobile-sdk-reference Enables OneSignal to manage the lifecycle of Live Activities within your application. This includes handling token updates for starting and updating Live Activities, which must be initiated when your application is in the foreground. ```APIDOC ## Live Activity Applications should allow users to opt-in to Live Activities. For example, your app gives the user the option to start the Live Activity within your US using a button or presenting an IAM. You may start and update a Live Activity via any method without an explicit prompt, unlike Notification Permission or Location Permission. Live Activities appear with the iOS Provisional Authorization UI. Live Activities must be started when your application is in the foreground. We recommend reading [Apple’s developer guidelines](https://developer.apple.com/design/human-interface-guidelines/live-activities) to learn more about Live Activities. ### `setup()` Allows OneSignal to manage the lifecycle of a LiveActivity on behalf of the application. This includes listening for both pushToStart token updates and pushToUpdate token updates. ### Swift ```swift //... your app's code OneSignal.LiveActivities.setup(MyWidgetAttributes.self); ``` ``` -------------------------------- ### Install OneSignal Capacitor Plugin Source: https://documentation.onesignal.com/docs/en/capacitor-sdk-setup Install the `@onesignal/capacitor-plugin` package and sync native dependencies. ```shell npm install @onesignal/capacitor-plugin npx cap sync ``` -------------------------------- ### Complete Example: Button Click to Tag User Source: https://documentation.onesignal.com/docs/en/in-app-message-api An example demonstrating how to attach an event listener to a button to tag the user with custom data when clicked. ```HTML ``` -------------------------------- ### Start Backend Server Source: https://documentation.onesignal.com/docs/en/identity-verification Run your Node.js server to handle JWT generation requests. This command starts the server that will be used to test JWT generation. ```bash node server.js ``` -------------------------------- ### Start a Live Notification on Android Source: https://documentation.onesignal.com/docs/en/android-live-notifications Send the 'start' event to create a live notification. Initialize both static and dynamic data. Ensure the `collapse_id` is unique for this notification instance. ```bash curl -X POST "https://api.onesignal.com/notifications" \ -H "Authorization: Key YOUR_APP_API_KEY" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "app_id": "YOUR_APP_ID", "isAndroid": true, "collapse_id": "UNIQUE_LIVE_NOTIFICATION_ID", "data": { "live_notification": { "key": "progress", "event": "start", "event_attributes": {}, "event_updates": { "current_progress": 0 } } }, "headings": { "en": "Start" }, "contents": { "en": "Starting Live Notification" }, "include_aliases": { "external_id": ["EID1", "EID2"] }, "target_channel": "push" }' ``` -------------------------------- ### Start Live Notification Source: https://documentation.onesignal.com/docs/en/android-live-notifications Initiates a live notification by sending an 'start' event. This call initializes both static and dynamic data for the notification. ```APIDOC ## POST /notifications ### Description Send an 'start' event to create a live notification. Initialize static (`event_attributes`) and dynamic (`event_updates`) data. ### Method POST ### Endpoint https://api.onesignal.com/notifications ### Request Body - **app_id** (string) - Required - Your OneSignal App ID. - **isAndroid** (boolean) - Required - Set to `true` to restrict delivery to Android push subscriptions. - **collapse_id** (string) - Required - A unique ID for this live notification instance to enable collapsing. - **data** (object) - Required - Contains live notification specific data. - **live_notification** (object) - Required - Defines the live notification. - **key** (string) - Required - A key identifying the type of live notification (e.g., 'progress'). - **event** (string) - Required - Must be set to 'start'. - **event_attributes** (object) - Optional - Static data for the notification. - **event_updates** (object) - Optional - Initial dynamic data for the notification. - **headings** (object) - Required - Notification headings in different languages. - **contents** (object) - Required - Notification content in different languages. - **include_aliases** (object) - Required - User identifiers to target. - **external_id** (array) - Required - Array of external IDs to send the notification to. - **target_channel** (string) - Required - Set to 'push' for push notifications. ### Request Example ```json { "app_id": "YOUR_APP_ID", "isAndroid": true, "collapse_id": "UNIQUE_LIVE_NOTIFICATION_ID", "data": { "live_notification": { "key": "progress", "event": "start", "event_attributes": {}, "event_updates": { "current_progress": 0 } } }, "headings": { "en": "Start" }, "contents": { "en": "Starting Live Notification" }, "include_aliases": { "external_id": ["EID1", "EID2"] }, "target_channel": "push" } ``` ``` -------------------------------- ### Example os_sdk payload Source: https://documentation.onesignal.com/docs/en/mobile-sdk-reference An example of the automatically included app-specific data under the reserved 'os_sdk' key in the properties payload for custom events. ```json { "os_sdk": { "sdk": "050213", "device_os": "18.5", "type": "iOSPush", "device_model": "iPhone14,4", "device_type": "ios", "app_version": "5.4.0" } } ``` -------------------------------- ### setupDefault() and startDefault() Source: https://documentation.onesignal.com/docs/en/mobile-sdk-reference Allows cross-platform SDKs to manage the lifecycle of a Live Activity. `setupDefault()` initializes the Live Activity management, and `startDefault()` launches the Live Activity from within the app. ```APIDOC ## `setupDefault()` and `startDefault()` ### Description Allows cross platform SDK's to manage the lifecycle of a LiveActivity by eliminating the need for a customer app to define and manage their own ActivityAttributes. See [Cross-platform setup](./cross-platform-live-activity-setup) for further details. ### Usage **Push To Start:** ```csharp OneSignal.LiveActivities.SetupDefault(); ``` **Launching the Live Activity from within the app (not needed for push to start):** ```csharp string activityId = "my_activity_id"; OneSignal.LiveActivities.StartDefault( activityId, new Dictionary() { { "title", "Welcome!" } }, new Dictionary() { { "message", new Dictionary() { { "en", "Hello World!"} }}, }); ``` ### React Native Example ```javascript import { OneSignal } from 'react-native-onesignal' //Push To Start OneSignal.LiveActivities.setupDefault() //Launching the Live Activity from within the app (not needed for push to start) const activityId = "my_activity_id" const attributes = { title: "Sample Title" } ; const content = { message: { en: "message" } }; OneSignal.LiveActivities.startDefault(activityId, attributes, content); ``` ### Flutter Example ```dart import 'package:onesignal_flutter/onesignal_flutter.dart'; OneSignal.LiveActivities.setupDefault() //Launching the Live Activity from within the app (not needed for push to start) const String activityId = "my_activity_id"; OneSignal.LiveActivities.startDefault(activityId!, { "title": "Welcome!" }, { "message": {"en": "Hello World!"}, }); ``` ### Cordova/Ionic Example ```javascript //Ionic import OneSignal from "onesignal-cordova-plugin"; //Push To Start OneSignal.LiveActivities.setupDefault(); //Launching the Live Activity from within the app (not needed for push to start) const activityId = "my_activity_id"; const attributes = { title: "Sample Title" }; const content = { message: { en: "message" } }; OneSignal.LiveActivities.startDefault(activityId, attributes, content); //Cordova //Push To Start window.plugins.OneSignal.LiveActivities.setupDefault(); //Launching the Live Activity from within the app (not needed for push to start) const activityId = "my_activity_id"; const attributes = { title: "Sample Title" }; const content = { message: { en: "message" } }; window.plugins.OneSignal.LiveActivities.startDefault( activityId, attributes, content ); ``` ``` -------------------------------- ### Configure Go SDK Source: https://documentation.onesignal.com/docs/en/server-sdk-reference Initialize the Go SDK with your API keys using context values. This setup is necessary before making any API calls. ```go import onesignal "github.com/OneSignal/onesignal-go-api" restAuth := context.WithValue( context.Background(), onesignal.RestApiKey, "YOUR_REST_API_KEY", ) orgAuth := context.WithValue( restAuth, onesignal.OrganizationApiKey, "YOUR_ORGANIZATION_API_KEY", ) apiClient := onesignal.NewAPIClient(onesignal.NewConfiguration()) ``` -------------------------------- ### Setup Live Activities Source: https://documentation.onesignal.com/docs/en/mobile-sdk-reference Allows OneSignal to manage the lifecycle of a Live Activity. This includes listening for pushToStart and pushToUpdate token updates. Ensure your application is in the foreground when starting a Live Activity. ```swift //... your app's code OneSignal.LiveActivities.setup(MyWidgetAttributes.self); ``` -------------------------------- ### Huawei Push Token Error Example Source: https://documentation.onesignal.com/docs/en/huawei-flutter-sdk-setup This log snippet indicates an issue with obtaining the Huawei push token. Check your Proguard or R8 rules for proper setup, or consider disabling them temporarily to diagnose the problem. ```log E/OneSignal: HMS ApiException getting Huawei push token! com.huawei.hms.common.ApiException: -5: Core error ``` -------------------------------- ### Store and Retrieve Badge Count using UserDefaults Source: https://documentation.onesignal.com/docs/en/badges Since iOS does not provide a system method to get the current badge count, you must manage it yourself. This example shows how to use UserDefaults to store and retrieve the badge count. ```swift // Example: Store and retrieve badge count using UserDefaults let badgeCount = UserDefaults.standard.integer(forKey: "badgeCount") // Update badge count as needed UserDefaults.standard.set(badgeCount, forKey: "badgeCount") ``` -------------------------------- ### Initialize and Control Onboarding Carousel Source: https://documentation.onesignal.com/docs/en/in-app-onboarding-carousel-tutorial This JavaScript code initializes the carousel, handles card transitions, and manages the 'Next' and 'Get Started' button actions. It also includes logic to dismiss the in-app message using the OneSignal IAM API. ```javascript document.getElementById("card-1").className = i === 1 ? "card active" : "card"; // Update progress dots var dots = document.getElementById("dots").children; dots[0].classList.toggle("active", i === 0); dots[1].classList.toggle("active", i === 1); } // Button: Next (card 0 → card 1) document.getElementById("next-0").addEventListener("click", function () { setActive(1); }); // Button: Get Started (dismisses the In-App Message) document.getElementById("done").addEventListener("click", function (e) { // Check if OneSignal IAM API is available if (window.OneSignalIamApi && OneSignalIamApi.close) { OneSignalIamApi.close(e); // Dismiss the message } }); })(); ``` -------------------------------- ### Setup Default Live Activity (Unity) Source: https://documentation.onesignal.com/docs/cn/cross-platform-live-activity-setup Use `OneSignal.LiveActivities.SetupDefault()` to allow the SDK to manage `DefaultLiveActivityAttributes`. The `StartDefault` method can be used to launch a live activity from your application. ```csharp using OneSignalSDK; //推送启动 OneSignal.LiveActivities.SetupDefault(); //从应用内启动实时活动(推送启动不需要) string activityId = "my_activity_id"; OneSignal.LiveActivities.StartDefault( activityId, new Dictionary() { { "title", "欢迎!" } }, new Dictionary() { { "message", new Dictionary() { { "en", "你好世界!"} }}, }); ``` -------------------------------- ### Setup Default Live Activity Management Source: https://documentation.onesignal.com/docs/en/cross-platform-live-activity-setup Call `setupDefault` to enable OneSignal's management of the Live Activity lifecycle for the default attributes type. This allows starting and updating Live Activities via push notifications or directly from the app. ```javascript import { OneSignal } from 'react-native-onesignal' //Push To Start OneSignal.LiveActivities.setupDefault() //Launching the Live Activity from within the app (not needed for push to start) const activityId = "my_activity_id" const attributes = { title: "Sample Title" } ; const content = { message: { en: "message" } }; OneSignal.LiveActivities.startDefault(activityId, attributes, content); ``` ```csharp using OneSignalSDK; //Push To Start OneSignal.LiveActivities.SetupDefault(); //Launching the Live Activity from within the app (not needed for push to start) string activityId = "my_activity_id"; OneSignal.LiveActivities.StartDefault( activityId, new Dictionary() { { "title", "Welcome!" } }, new Dictionary() { { "message", new Dictionary() { { "en", "Hello World!"} }}, }); ``` ```javascript /*Cordova*/ //Push To Start window.plugins.OneSignal.LiveActivities.setupDefault(); //Launching the Live Activity from within the app (not needed for push to start) const activityId = "my_activity_id"; const attributes = { title: "Sample Title" }; const content = { message: { en: "message" } }; window.plugins.OneSignal.LiveActivities.startDefault( activityId, attributes, content ); /*Ionic/Capacitor*/ import OneSignal from "onesignal-cordova-plugin"; //Push To Start OneSignal.LiveActivities.setupDefault(); //Launching the Live Activity from within the app (not needed for push to start) const activityId = "my_activity_id"; const attributes = { title: "Sample Title" }; const content = { message: { en: "message" } }; OneSignal.LiveActivities.startDefault(activityId, attributes, content); ``` ```csharp using OneSignalSDK; //Push To Start OneSignal.LiveActivities.SetupDefault(); //Launching the Live Activity from within the app (not needed for push to start) string activityId = "my_activity_id"; OneSignal.LiveActivities.StartDefault( activityId, new Dictionary() { { "title", "Welcome!" } }, new Dictionary() { { "message", new Dictionary() { { "en", "Hello World!"} }}, }); ``` ```javascript import 'package:onesignal_flutter/onesignal_flutter.dart'; OneSignal.LiveActivities.setupDefault() //Launching the Live Activity from within the app (not needed for push to start) const String activityId = "my_activity_id"; OneSignal.LiveActivities.startDefault(activityId!, { "title": "Welcome!" }, { "message": {"en": "Hello World!"}, }); ``` -------------------------------- ### Full Podfile Example with Multiple Targets Source: https://documentation.onesignal.com/docs/en/live-activities-developer-setup This example shows a complete Podfile configuration including OneSignal for multiple targets, such as the main app, notification service extension, and widget extension. ```ruby # Uncomment the next line to define a global platform for your project # platform :ios, '9.0' target 'Demo Momenta' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! pod 'OneSignal/OneSignal', '>= 5.0.0', '< 6.0' pod 'OneSignal/OneSignalInAppMessages', '>= 5.0.0', '< 6.0' end target 'OneSignalNotificationServiceExtension' do use_frameworks! pod 'OneSignal/OneSignal', '>= 5.0.0', '< 6.0' end target 'OneSignalWidgetExtension' do use_frameworks! pod 'OneSignal/OneSignal', '>= 5.0.0', '< 6.0' end ``` -------------------------------- ### Configure Python SDK Source: https://documentation.onesignal.com/docs/en/server-sdk-reference Set up the Python SDK by providing your REST API Key and Organization API Key. Use a client context manager for proper resource handling. ```python import onesignal from onesignal.api import default_api configuration = onesignal.Configuration( rest_api_key='YOUR_REST_API_KEY', organization_api_key='YOUR_ORGANIZATION_API_KEY', ) with onesignal.ApiClient(configuration) as api_client: client = default_api.DefaultApi(api_client); ``` -------------------------------- ### Install iOS Pods Source: https://documentation.onesignal.com/docs/en/capacitor-sdk-setup After updating the Podfile, navigate to the ios directory and run 'pod install' to integrate the OneSignal SDK. This command installs all the necessary native dependencies for iOS. ```shell cd ios pod install cd .. ``` -------------------------------- ### Create a New React App Source: https://documentation.onesignal.com/docs/en/react-js-setup Use Create React App to quickly set up a new React project with a pre-configured build and development environment. This is the recommended way to start new single-page applications. ```bash npx create-react-app my-app cd my-app npm start ``` -------------------------------- ### Install onesignal-ngx Package Source: https://documentation.onesignal.com/docs/en/angular-setup Install the onesignal-ngx package using npm or yarn. ```bash npm install --save onesignal-ngx ``` ```bash yarn add onesignal-ngx ``` -------------------------------- ### Install OneSignal Expo Plugin Source: https://documentation.onesignal.com/docs/en/react-native-expo-sdk-setup Install the OneSignal Expo plugin using the Expo CLI. ```shell npx expo install onesignal-expo-plugin ``` -------------------------------- ### Install React Native OneSignal SDK Source: https://documentation.onesignal.com/docs/en/react-native-sdk-setup Install the react-native-onesignal package using your preferred package manager. ```shell npm install --save react-native-onesignal ``` ```shell yarn add react-native-onesignal ``` ```shell bun add react-native-onesignal ``` -------------------------------- ### Start Live Activity API Request Source: https://documentation.onesignal.com/docs/en/cross-platform-live-activity-setup Use this cURL command to start a Live Activity. Ensure you replace YOUR_APP_ID and YOUR_REST_API_KEY with your actual credentials. The `activity_id` determines if a new Live Activity is started or an existing one is updated. ```curl curl --request POST \ --url https://api.onesignal.com/apps/YOUR_APP_ID/activities/activity/DefaultLiveActivityAttributes \ --header 'Authorization: key YOUR_REST_API_KEY' \ --header 'Content-Type: application/json' \ --header 'accept: application/json' \ --data \ '{ "event": "start", "event_updates": { "data": { "message": { "en": "The message is nested in context.state.data[\"message\"] as a dictionary" }, "intValue": 10, "doubleValue": 3.14, "boolValue": true } }, "event_attributes": { "data": { "title": "this is set when the LA starts and does not get updated after" } }, "activity_id": "my-activity-id", "name": "OneSignal Notification Name", "contents": { "en": "English Message" }, "headings": { "en": "English Message" }, "sound": "beep.wav", "priority": 10 }' ``` -------------------------------- ### Configure PHP SDK Source: https://documentation.onesignal.com/docs/en/server-sdk-reference Set up the PHP SDK using Guzzle HTTP client and provide your API keys. Ensure the configuration is correctly applied to the client. ```php use onesignal\client\api\DefaultApi; use onesignal\client\Configuration; use GuzzleHttp; $config = Configuration::getDefaultConfiguration() ->setRestApiKeyToken('YOUR_REST_API_KEY') ->setOrganizationApiKeyToken('YOUR_ORGANIZATION_API_KEY'); $client = new DefaultApi( new GuzzleHttp\Client(), $config ); ``` -------------------------------- ### Configure Java SDK Source: https://documentation.onesignal.com/docs/en/server-sdk-reference Initialize the Java SDK with your API keys. This involves setting up authentication for both REST and Organization API keys. ```java import com.onesignal.client.ApiClient; import com.onesignal.client.Configuration; import com.onesignal.client.auth.HttpBearerAuth; import com.onesignal.client.api.DefaultApi; ApiClient defaultClient = Configuration.getDefaultApiClient(); HttpBearerAuth restApiAuth = (HttpBearerAuth) defaultClient .getAuthentication("rest_api_key"); restApiAuth.setBearerToken("YOUR_REST_API_KEY"); HttpBearerAuth orgApiAuth = (HttpBearerAuth) defaultClient .getAuthentication("organization_api_key"); orgApiAuth.setBearerToken("YOUR_ORGANIZATION_API_KEY"); DefaultApi client = new DefaultApi(defaultClient); ``` -------------------------------- ### Start Live Activity via Push Notification Source: https://documentation.onesignal.com/docs/en/live-activities-developer-setup Use this cURL command to start a Live Activity remotely using OneSignal's Push To Start API. Ensure your App ID, API Key, and widget attribute names are correctly configured. ```bash curl --location 'https://api.onesignal.com/apps/YOUR_APP_ID/activities/activity/OneSignalWidgetAttributes' \ --header 'Authorization: key YOUR_APP_API_KEY' \ --header 'Content-Type: application/json' \ --data '{ "event": "start", "activity_id": "push-to-start", "included_segments": [ "Subscribed Users" ], "event_attributes": { "name": "World" }, "event_updates": { "emoji":"🤩" }, "name": "Live Activities Test", "contents": { "en": "A push started this Live Activity" }, "headings": { "en": "Live Activity Started" } }' ``` -------------------------------- ### Set Push to Start Token for Live Activities Source: https://documentation.onesignal.com/docs/en/mobile-sdk-reference Optional low-level approach to push to start Live Activities. Offers fine-grained control over Live Activity start and update tokens without altering the ActivityAttribute structure. Requires iOS 17.2 or later. ```Swift if #available(iOS 17.2, *) { // Setup an async task to monitor and send pushToStartToken updates to OneSignalSDK. Task { for try await data in Activity.pushToStartTokenUpdates { let token = data.map {String(format: "%02x", $0)}.joined() OneSignal.LiveActivities.setPushToStartToken(MyWidgetAttributes.self, withToken: token) } } // Setup an async task to monitor for an activity to be started, for each started activity we // can then set up an async task to monitor and send updateToken updates to OneSignalSDK. Task { for await activity in Activity.activityUpdates { Task { for await pushToken in activity.pushTokenUpdates { let token = pushToken.map {String(format: "%02x", $0)}.joined() OneSignal.LiveActivities.enter("my-activity-id", withToken: token) } } } } } ``` -------------------------------- ### Configure C# (.NET) SDK Source: https://documentation.onesignal.com/docs/en/server-sdk-reference Initialize the C# SDK by setting the BasePath and AccessToken (REST API Key). The Organization API Key is not directly used in this client initialization. ```csharp using OneSignalApi.Api; using OneSignalApi.Client; var config = new Configuration(); config.BasePath = "https://api.onesignal.com"; config.AccessToken = "YOUR_REST_API_KEY"; var client = new DefaultApi(config); ``` -------------------------------- ### Initialize OneSignal SDK Source: https://documentation.onesignal.com/docs/en/web-sdk-setup Copy and paste this code into your website's `` tags to initialize the OneSignal SDK. Replace 'YOUR_ONESIGNAL_APP_ID' with your actual App ID. ```html ``` -------------------------------- ### Initialize OneSignal SDK with Custom Code Setup Source: https://documentation.onesignal.com/docs/en/web-sdk-reference This snippet demonstrates how to initialize the OneSignal Web SDK using a custom code setup. It includes configuration for the Subscription Bell and advanced prompt options for SMS/Email and category-based subscriptions. ```javascript ```