From 8ae6275441173883d3af47a3933b772aad43024e Mon Sep 17 00:00:00 2001 From: Jenna Antilla <46546946+jennantilla@users.noreply.github.com> Date: Tue, 20 Jun 2023 11:19:24 -0700 Subject: [PATCH 01/29] run Prettier for linting test failure --- .github/ISSUE_TEMPLATE/ask-question.yml | 4 +- .github/ISSUE_TEMPLATE/bug-report.yml | 4 +- .github/ISSUE_TEMPLATE/general-feedback.yml | 4 +- .github/pull_request_template.md | 67 +- .github/release-drafter.yml | 6 +- .github/workflows/Zapier.yml | 2 +- .github/workflows/ci.yml | 8 +- .github/workflows/release-drafter.yml | 1 - CONTRIBUTING.md | 17 +- MIGRATION_GUIDE.md | 299 +++--- README.md | 6 +- examples/RNOneSignalTS/.watchmanconfig | 2 +- examples/RNOneSignalTS/app.json | 2 +- .../AppIcon.appiconset/Contents.json | 46 +- .../Images.xcassets/Contents.json | 6 +- examples/RNOneSignalTS/src/App.tsx | 4 +- examples/RNOneSignalTS/src/Helpers.tsx | 117 ++- examples/RNOneSignalTS/src/OSButtons.tsx | 954 +++++++++--------- examples/RNOneSignalTS/src/OSConsole.tsx | 82 +- examples/RNOneSignalTS/src/OSDemo.tsx | 32 +- examples/RNOneSignalTS/tsconfig.json | 30 +- jest.config.js | 22 +- src/index.ts | 235 +++-- src/models/InAppMessage.ts | 19 +- src/models/NotificationEvents.ts | 4 +- src/models/Subscription.ts | 2 +- tsconfig.json | 14 +- 27 files changed, 1038 insertions(+), 951 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/ask-question.yml b/.github/ISSUE_TEMPLATE/ask-question.yml index dce598c6..f5ad8501 100644 --- a/.github/ISSUE_TEMPLATE/ask-question.yml +++ b/.github/ISSUE_TEMPLATE/ask-question.yml @@ -1,7 +1,7 @@ name: 🙋‍♂️ Ask a question description: Tell us what's on your mind -title: "[question]: " -labels: ["question"] +title: '[question]: ' +labels: ['question'] # assignees: # - OneSignal/ios-sdk body: diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index a80fde12..2c8e9351 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -1,7 +1,7 @@ name: 🪳 Bug report description: File a bug report -title: "[Bug]: " -labels: ["bug", "triage"] +title: '[Bug]: ' +labels: ['bug', 'triage'] # assignees: # - OneSignal/ios-sdk body: diff --git a/.github/ISSUE_TEMPLATE/general-feedback.yml b/.github/ISSUE_TEMPLATE/general-feedback.yml index fbada335..0776fab6 100644 --- a/.github/ISSUE_TEMPLATE/general-feedback.yml +++ b/.github/ISSUE_TEMPLATE/general-feedback.yml @@ -1,7 +1,7 @@ name: 📣 General feedback description: Tell us what's on your mind -title: "[Feedback]: " -labels: ["triage"] +title: '[Feedback]: ' +labels: ['triage'] # assignees: # - OneSignal/ios-sdk body: diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 1ce9a81a..ad828eb8 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,60 +1,75 @@ + # READ AND DELETE THIS SECTION BEFORE SUBMITTING PR -* **Fill out each _REQUIRED_ section** -* **Fill out _OPTIONAL_ sections, remove section if it doesn't apply to your PR** -* **Read and fill out each of the checklists below** -* **Remove this section after reading** + +- **Fill out each _REQUIRED_ section** +- **Fill out _OPTIONAL_ sections, remove section if it doesn't apply to your PR** +- **Read and fill out each of the checklists below** +- **Remove this section after reading** # Description + ## One Line Summary + **REQUIRED** - Very short description that summaries the changes in this PR. ## Details ### Motivation + **REQUIRED -** Why is this code change being made? Or what is the goal of this PR? Examples: Fixes a specific bug, provides additional logging to debug future issues, feature to allow X. ### Scope + **RECOMMEND - OPTIONAL -** What is intended to be effected. What is known not to change. Example: Notifications are grouped when parameter X is set, not enabled by default. ### OPTIONAL - Other + **OPTIONAL -** Feel free to add any other sections or sub-sections that can explain your PR better. # Testing + ## Unit testing -**OPTIONAL -** Explain unit tests added, if not clear in the code. + +**OPTIONAL -** Explain unit tests added, if not clear in the code. ## Manual testing + **RECOMMEND - OPTIONAL -** Explain what scenarios were tested and the environment. Example: Tested opening a notification while the app was foregrounded, app build with Android Studio 2020.3 with a fresh install of the OneSignal example app on a Pixel 6 with Android 12. # Affected code checklist - - [ ] Notifications - - [ ] Display - - [ ] Open - - [ ] Push Processing - - [ ] Confirm Deliveries - - [ ] Outcomes - - [ ] Sessions - - [ ] In-App Messaging - - [ ] REST API requests - - [ ] Public API changes + +- [ ] Notifications + - [ ] Display + - [ ] Open + - [ ] Push Processing + - [ ] Confirm Deliveries +- [ ] Outcomes +- [ ] Sessions +- [ ] In-App Messaging +- [ ] REST API requests +- [ ] Public API changes # Checklist + ## Overview - - [ ] 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 - - [ ] Any Public API changes are explained in the PR details and conform to existing APIs + +- [ ] 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 +- [ ] Any Public API changes are explained in the PR details and conform to existing APIs ## Testing - - [ ] I have included test coverage for these changes, or explained why they are not needed - - [ ] All automated tests pass, or I explained why that is not possible - - [ ] I have personally tested this on my device, or explained why that is not possible + +- [ ] I have included test coverage for these changes, or explained why they are not needed +- [ ] All automated tests pass, or I explained why that is not possible +- [ ] I have personally tested this on my device, or explained why that is not possible ## Final pass - - [ ] 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. - - [ ] 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. \ No newline at end of file + +- [ ] 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. +- [ ] 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. diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index a7a42bde..5591cb45 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -6,9 +6,9 @@ categories: - title: 🐛 Bug Fixes label: Bug - title: 🧰 Improvements - label: Improvement + label: Improvement - title: down arrow Dependency Updates - label: Dependencies + label: Dependencies change-template: '- $TITLE (#$NUMBER)' version-resolver: major: @@ -23,5 +23,5 @@ version-resolver: default: patch template: | ## Other Changes - + $CHANGES diff --git a/.github/workflows/Zapier.yml b/.github/workflows/Zapier.yml index 3665dd58..5aab0bbf 100644 --- a/.github/workflows/Zapier.yml +++ b/.github/workflows/Zapier.yml @@ -7,7 +7,7 @@ on: # Triggers the workflow on push or pull request events but only for the "main" branch issues: types: [closed] - + permissions: issues: read diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af204294..eac8cfbf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,20 +2,20 @@ name: Test on: pull_request: - branches: "**" + branches: '**' jobs: build: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - - name: "[Setup] Node" + - name: '[Setup] Node' uses: actions/setup-node@v3 with: node-version: 16 - - name: "[Setup] Dependencies" + - name: '[Setup] Dependencies' run: yarn - - name: "[Test] Linting" + - name: '[Test] Linting' run: yarn lint - name: Unit tests results diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index a64b3721..82e66d26 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -1,4 +1,3 @@ - name: Release Drafter on: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e13790dd..282a6ee1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,6 +3,7 @@ :+1::tada: First off, thanks for taking the time to contribute! :tada::+1: ### How to Contribute + We love the open source community and enjoy the support and contributions of many of our users. We ask that any potential contributors to the SDK Follow the following guidelines: If your proposed contribution is a small bug fix, please feel free to create your own fork of the repository and create a pull request. @@ -10,13 +11,15 @@ If your proposed contribution is a small bug fix, please feel free to create you If your contribution would _break_ or _change_ the functionality of the SDK, please reach out to us on (contact) before you put in a lot of effort into a change we may not be able to use. We try our best to make sure that the SDK remains stable so that developers do not have to continually change their code, however some breaking changes _are_ desirable, so please get in touch to discuss your idea before you put in a lot of effort. #### Reporting Bugs -If you have found a bug with the SDK, please feel free to open an Issue. + +If you have found a bug with the SDK, please feel free to open an Issue. If you are pretty certain that the issue is only related to the native iOS SDK, please open the issue in our [native iOS SDK repository](https://github.com/OneSignal/OneSignal-iOS-SDK). If you are certain the issue is contained to the Android SDK, please open the issue in our [Android SDK repository](https://github.com/OneSignal/OneSignal-Android-SDK) #### Before Submitting A Bug Report + Before creating bug reports, please check this list of steps to follow. 1. Make sure that you are actually encountering an _issue_ and not a _question_. If you simply have a question about the SDK, we would be more than happy to assist you in our Support section on the web (https://www.onesignal.com - click the Message button at the bottom right) @@ -24,10 +27,10 @@ Before creating bug reports, please check this list of steps to follow. > **Note:** If you find a **Closed** issue that seems like it is the same thing that you're experiencing, open a new issue and include a link to the original issue in the body of your new one. - #### How Do I Submit a Good Bug Report -* **Use a clear and descriptive title** for the issue to identify the problem. -* **Include Reproducibility** It is nearly always a good idea to include steps to reproduct the issue. If you cannot reliably reproduce the issue yourself, that's ok, but reproducible steps help best. -* **Describe your environment**, tell us what version of react-native your app is using, what version of the react-native-onesignal SDK you're using, how you added it to your project, and so on. -* **Include a Stack Trace** If your issue involves a crash/exception, ***PLEASE*** post the stack trace to help us identify the root issue. -* **Include an Example Project** This isn't required, but if you want your issue fixed quickly, it's often a good idea to include an example project as a zip and include it with the issue. You can also download the Demo project (included in the `/examples` folder of this repo) and set up an example project with this code as a starting point. + +- **Use a clear and descriptive title** for the issue to identify the problem. +- **Include Reproducibility** It is nearly always a good idea to include steps to reproduct the issue. If you cannot reliably reproduce the issue yourself, that's ok, but reproducible steps help best. +- **Describe your environment**, tell us what version of react-native your app is using, what version of the react-native-onesignal SDK you're using, how you added it to your project, and so on. +- **Include a Stack Trace** If your issue involves a crash/exception, **_PLEASE_** post the stack trace to help us identify the root issue. +- **Include an Example Project** This isn't required, but if you want your issue fixed quickly, it's often a good idea to include an example project as a zip and include it with the issue. You can also download the Demo project (included in the `/examples` folder of this repo) and set up an example project with this code as a starting point. diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index 9095189a..3d1588c9 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -18,25 +18,26 @@ A user is a new concept which is meant to represent your end-user. A user has ze ## Subscription -A subscription refers to the method in which an end-user can receive various communications sent by OneSignal, including push notifications, SMS, and email. In previous versions of the OneSignal platform, each of these channels was referred to as a “player”. A subscription is in fact identical to the legacy “player” concept. Each subscription has a **subscription_id** (previously, player_id) to uniquely identify that communication channel. +A subscription refers to the method in which an end-user can receive various communications sent by OneSignal, including push notifications, SMS, and email. In previous versions of the OneSignal platform, each of these channels was referred to as a “player”. A subscription is in fact identical to the legacy “player” concept. Each subscription has a **subscription_id** (previously, player_id) to uniquely identify that communication channel. ## Aliases -Aliases are a concept evolved from [external user ids](https://documentation.onesignal.com/docs/external-user-ids) which allows the unique identification of a user within a OneSignal application. Aliases are a key-value pair made up of an **alias label** (the key) and an **alias id** (the value). The **alias label** can be thought of as a consistent keyword across all users, while the **alias id** is a value specific to each user for that particular label. The combined **alias label** and **alias id** provide uniqueness to successfully identify a user. +Aliases are a concept evolved from [external user ids](https://documentation.onesignal.com/docs/external-user-ids) which allows the unique identification of a user within a OneSignal application. Aliases are a key-value pair made up of an **alias label** (the key) and an **alias id** (the value). The **alias label** can be thought of as a consistent keyword across all users, while the **alias id** is a value specific to each user for that particular label. The combined **alias label** and **alias id** provide uniqueness to successfully identify a user. -OneSignal uses a built-in **alias label** called `external_id` which supports existing use of [external user ids](https://documentation.onesignal.com/docs/external-user-ids). `external_id` is also used as the identification method when a user identifies themselves to the OneSignal SDK via `OneSignal.login`. Multiple aliases can be created for each user to allow for your own application's unique identifier as well as identifiers from other integrated applications. +OneSignal uses a built-in **alias label** called `external_id` which supports existing use of [external user ids](https://documentation.onesignal.com/docs/external-user-ids). `external_id` is also used as the identification method when a user identifies themselves to the OneSignal SDK via `OneSignal.login`. Multiple aliases can be created for each user to allow for your own application's unique identifier as well as identifiers from other integrated applications. # Migration Guide (v3 to v5) The React Native SDK accesses the OneSignal native iOS and Android SDKs. For this update, all SDK versions are aligning across OneSignal’s suite of client SDKs. As such, the React Native SDK is making the jump from `v3` to `v5`. # API Changes + ## Namespaces The OneSignal SDK has been updated to be more modular in nature. The SDK has been split into namespaces, and functionality previously in the static `OneSignal` class has been moved to the appropriate namespace. The namespaces and how to access them in code are as follows: | **Namespace** | **Access Pattern** | -| ------------- | -------------------------- | +| -------------- | -------------------------- | | Debug | `OneSignal.Debug` | | InAppMessages | `OneSignal.InAppMessages` | | LiveActivities | `OneSignal.LiveActivities` | @@ -53,23 +54,22 @@ Navigate to your index.ts file, or the first Javascript file that loads with you Replace the following: - ```typescript - OneSignal.setAppId("YOUR_ONESIGNAL_APP_ID"); +OneSignal.setAppId('YOUR_ONESIGNAL_APP_ID'); ``` To the match the new initialization: ```typescript - OneSignal.initialize("YOUR_ONESIGNAL_APP_ID"); +OneSignal.initialize('YOUR_ONESIGNAL_APP_ID'); ``` -If your integration is **not** user-centric, there is no additional startup code required. A device-scoped user *(please see definition of “**device-scoped user**” below in Glossary)* is automatically created as part of the push subscription creation, both of which are only accessible from the current device or through the OneSignal dashboard. +If your integration is **not** user-centric, there is no additional startup code required. A device-scoped user _(please see definition of “**device-scoped user**” below in Glossary)_ is automatically created as part of the push subscription creation, both of which are only accessible from the current device or through the OneSignal dashboard. If your integration is user-centric, or you want the ability to identify the user beyond the current device, the `login` method should be called to identify the user: ```typescript - OneSignal.User.login("USER_EXTERNAL_ID"); +OneSignal.User.login('USER_EXTERNAL_ID'); ``` The `login` method will associate the device’s push subscription to the user that can be identified via the alias `externalId=USER_EXTERNAL_ID`. If that user doesn’t already exist, it will be created. If the user does already exist, the user will be updated to own the device’s push subscription. Note that the push subscription for the device will always be transferred to the newly logged in user, as that user is the current owner of that push subscription. @@ -77,7 +77,7 @@ The `login` method will associate the device’s push subscription to the user t Once (or if) the user is no longer identifiable in your app (i.e. they logged out), the `logout` method should be called: ```typescript - OneSignal.User.logout(); +OneSignal.User.logout(); ``` Logging out has the affect of reverting to a device-scoped user, which is the new owner of the device’s push subscription. @@ -87,12 +87,15 @@ Logging out has the affect of reverting to a device-scoped user, which is the ne In previous versions of the SDK, a “player” could have up to one email address and up to one phone number for SMS. In the user-centered model, a user can own the current device’s **Push Subscription** along with the ability to have **zero or more** email subscriptions and **zero or more** SMS subscriptions. Note: If a new user logs in via the `login` method, the previous user will no longer own that push subscription. ### **Push Subscription** + The current device’s push subscription can be retrieved via: ```typescript - const id: string = await OneSignal.User.PushSubscription.getPushSubscriptionId(); - const token: string = await OneSignal.User.PushSubscription.getPushSubscriptionToken(); - const optedIn: boolean = await OneSignal.User.PushSubscription.getOptedIn(); +const id: string = + await OneSignal.User.PushSubscription.getPushSubscriptionId(); +const token: string = + await OneSignal.User.PushSubscription.getPushSubscriptionToken(); +const optedIn: boolean = await OneSignal.User.PushSubscription.getOptedIn(); ``` ### **Opting In and Out of Push Notifications** @@ -102,13 +105,13 @@ To receive push notifications on the device, call the push subscription’s `opt Note: For greater control over prompting for push notification permission, you may use the `OneSignal.Notifications.requestPermission` method detailed below in the API Reference. ```typescript - OneSignal.User.PushSubscription.optIn(); +OneSignal.User.PushSubscription.optIn(); ``` If at any point you want the user to stop receiving push notifications on the current device (regardless of system-level permission status), you can use the push subscription to opt out: ```typescript - OneSignal.User.PushSubscription.optOut(); +OneSignal.User.PushSubscription.optOut(); ``` To resume receiving of push notifications (driving the native permission prompt if permissions are not available), you can opt back in with the `optIn` method from above. @@ -118,15 +121,15 @@ To resume receiving of push notifications (driving the native permission prompt Email and/or SMS subscriptions can be added or removed via the following methods. The remove methods will result in a no-op if the specified email or SMS number does not exist on the user within the SDK, and no request will be made. ```typescript - // Add email subscription - OneSignal.User.addEmail("customer@company.com"); - // Remove previously added email subscription - OneSignal.User.removeEmail("customer@company.com"); - - // Add SMS subscription - OneSignal.User.addSms("+15558675309"); - // Remove previously added SMS subscription - OneSignal.User.removeSms("+15558675309"); +// Add email subscription +OneSignal.User.addEmail('customer@company.com'); +// Remove previously added email subscription +OneSignal.User.removeEmail('customer@company.com'); + +// Add SMS subscription +OneSignal.User.addSms('+15558675309'); +// Remove previously added SMS subscription +OneSignal.User.removeSms('+15558675309'); ``` # API Reference @@ -137,16 +140,14 @@ Below is a comprehensive reference to the `5.0.0-beta-02` OneSignal React Native The SDK is still accessible via a `OneSignal` static class. It provides access to higher level functionality and is a gateway to each subspace of the SDK. -|**React Native** | **Description** | -|-----------------------------------------------------------------------------------------------| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `OneSignal.initialize("YOUR_ONESIGNAL_APP_ID")` | *Initializes the OneSignal SDK. This should be called during startup of the application.* | -| `OneSignal.User.login("USER_EXTERNAL_ID")` | *Login to OneSignal under the user identified by the [externalId] provided. The act of logging a user into the OneSignal SDK will switch the [user] context to that specific user.

- If the [externalId] exists, the user will be retrieved and the context will be set from that user information. If operations have already been performed under a device-scoped user, they ***will not*** be applied to the now logged in user (they will be lost).
- If the [externalId] does not exist the user, the user will be created and the context set from the current local state. If operations have already been performed under a device-scoped user, those operations ***will*** be applied to the newly created user.

***Push Notifications and In App Messaging***
Logging in a new user will automatically transfer the push notification and in app messaging subscription from the current user (if there is one) to the newly logged in user. This is because both push notifications and in-app messages are owned by the device.* | -| `OneSignal.User.logout()` | *Logout the user previously logged in via [login]. The [user] property now references a new device-scoped user. A device-scoped user has no user identity that can later be retrieved, except through this device as long as the app remains installed and the app data is not cleared.* | -| `OneSignal.setConsentGiven(true)` | *Indicates whether privacy consent has been granted. This field is only relevant when the application has opted into data privacy protections. See [requiresPrivacyConsent].* | -| `OneSignal.setConsentRequired(true)` | *Determines whether a user must consent to privacy prior to their user data being sent up to OneSignal. This should be set to `true` prior to the invocation of `initialize` to ensure compliance.* | -| `OneSignal.setLaunchURLsInApp(true)` | *This method can be used to set if launch URLs should be opened in safari or within the application. Set to `true` to launch all notifications with a URL in the app instead of the default web browser. Make sure to call `setLaunchURLsInApp` before the `initialize` call.* | - - +| **React Native** | **Description** | +| ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `OneSignal.initialize("YOUR_ONESIGNAL_APP_ID")` | _Initializes the OneSignal SDK. This should be called during startup of the application._ | +| `OneSignal.User.login("USER_EXTERNAL_ID")` | \*Login to OneSignal under the user identified by the [externalId] provided. The act of logging a user into the OneSignal SDK will switch the [user] context to that specific user.

- If the [externalId] exists, the user will be retrieved and the context will be set from that user information. If operations have already been performed under a device-scoped user, they **_will not_** be applied to the now logged in user (they will be lost).
- If the [externalId] does not exist the user, the user will be created and the context set from the current local state. If operations have already been performed under a device-scoped user, those operations **_will_** be applied to the newly created user.

**_Push Notifications and In App Messaging_**
Logging in a new user will automatically transfer the push notification and in app messaging subscription from the current user (if there is one) to the newly logged in user. This is because both push notifications and in-app messages are owned by the device.\* | +| `OneSignal.User.logout()` | _Logout the user previously logged in via [login]. The [user] property now references a new device-scoped user. A device-scoped user has no user identity that can later be retrieved, except through this device as long as the app remains installed and the app data is not cleared._ | +| `OneSignal.setConsentGiven(true)` | _Indicates whether privacy consent has been granted. This field is only relevant when the application has opted into data privacy protections. See [requiresPrivacyConsent]._ | +| `OneSignal.setConsentRequired(true)` | _Determines whether a user must consent to privacy prior to their user data being sent up to OneSignal. This should be set to `true` prior to the invocation of `initialize` to ensure compliance._ | +| `OneSignal.setLaunchURLsInApp(true)` | _This method can be used to set if launch URLs should be opened in safari or within the application. Set to `true` to launch all notifications with a URL in the app instead of the default web browser. Make sure to call `setLaunchURLsInApp` before the `initialize` call._ | ## Live Activities Namespace @@ -154,70 +155,66 @@ Live Activities are a type of interactive push notification. Apple introduced th Please refer to OneSignal’s guide on [Live Activities](https://documentation.onesignal.com/docs/live-activities), the [Live Activities Quickstart](https://documentation.onesignal.com/docs/live-activities-quickstart) tutorial, and the [existing SDK reference](https://documentation.onesignal.com/docs/sdk-reference#live-activities) on Live Activities. -|**React Native** | **Description** | -| --------------------------------------------------------- | ---------------------------------------------------------------------------------------- | -| `OneSignal.LiveActivities.enter("ACTIVITY_ID", "TOKEN")`

***See below for usage of callbacks*** | *Entering a Live Activity associates an `activityId` with a live activity temporary push `token` on OneSignal's server. The activityId is then used with the OneSignal REST API to update one or multiple Live Activities at one time.* | -| `OneSignal.LiveActivities.exit("ACTIVITY_ID")`

***See below for usage of callbacks*** | *Exiting a Live activity deletes the association between a customer defined `activityId` with a Live Activity temporary push `token` on OneSignal's server.* | +| **React Native** | **Description** | +| ------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `OneSignal.LiveActivities.enter("ACTIVITY_ID", "TOKEN")`

**_See below for usage of callbacks_** | _Entering a Live Activity associates an `activityId` with a live activity temporary push `token` on OneSignal's server. The activityId is then used with the OneSignal REST API to update one or multiple Live Activities at one time._ | +| `OneSignal.LiveActivities.exit("ACTIVITY_ID")`

**_See below for usage of callbacks_** | _Exiting a Live activity deletes the association between a customer defined `activityId` with a Live Activity temporary push `token` on OneSignal's server._ | + ```typescript - // Enter a Live Activity - OneSignal.LiveActivities.enter("ACTIVITY_ID", "TOKEN", (results) => { - console.log("Results of entering live activity"); - console.log(results); - }); - - // Exit a Live Activity - OneSignal.LiveActivities.exit("ACTIVITY_ID", (results) => { - console.log("Results of exiting live activity"); - console.log(results); - }); +// Enter a Live Activity +OneSignal.LiveActivities.enter('ACTIVITY_ID', 'TOKEN', (results) => { + console.log('Results of entering live activity'); + console.log(results); +}); + +// Exit a Live Activity +OneSignal.LiveActivities.exit('ACTIVITY_ID', (results) => { + console.log('Results of exiting live activity'); + console.log(results); +}); ``` ## User Namespace The User namespace is accessible via `OneSignal.User` and provides access to user-scoped functionality. - -|**React Native** | **Description** | -|------------------------------------------------------------------------------------------| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `OneSignal.User.setLanguage("en")` | *Set the 2-character language for this user.* | -| `OneSignal.User.addAlias("ALIAS_LABEL", "ALIAS_ID")` | *Set an alias for the current user. If this alias label already exists on this user, it will be overwritten with the new alias id.* | -| `OneSignal.User.addAliases({ALIAS_LABEL_01: "ALIAS_ID_01", ALIAS_LABEL_02: "ALIAS_ID_02"})` | *Set aliases for the current user. If any alias already exists, it will be overwritten to the new values.* | -| `OneSignal.User.removeAlias("ALIAS_LABEL")` | *Remove an alias from the current user.* | -| `OneSignal.User.removeAliases(["ALIAS_LABEL_01", "ALIAS_LABEL_02"]])` | *Remove aliases from the current user.* | -| `OneSignal.User.addEmail("customer@company.com")` | *Add a new email subscription to the current user.* | -| `OneSignal.User.removeEmail("customer@company.com")` | *Results in a no-op if the specified email does not exist on the user within the SDK, and no request will be made.* | -| `OneSignal.User.addSms("+15558675309")` | *Add a new SMS subscription to the current user.* | -| `OneSignal.User.removeSms("+15558675309")` | *Results in a no-op if the specified phone number does not exist on the user within the SDK, and no request will be made..* | -| `OneSignal.User.addTag("KEY", "VALUE")` | *Add a tag for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing messages. If the tag key already exists, it will be replaced with the value provided here.* | -| `OneSignal.User.addTags({"KEY_01": "VALUE_01", "KEY_02": "VALUE_02"})` | *Add multiple tags for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing messages. If the tag key already exists, it will be replaced with the value provided here.* | -| `OneSignal.User.removeTag("KEY")` | *Remove the data tag with the provided key from the current user.* | -| `OneSignal.User.removeTags(["KEY_01", "KEY_02"])` | *Remove multiple tags with the provided keys from the current user.* | - - +| **React Native** | **Description** | +| ------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `OneSignal.User.setLanguage("en")` | _Set the 2-character language for this user._ | +| `OneSignal.User.addAlias("ALIAS_LABEL", "ALIAS_ID")` | _Set an alias for the current user. If this alias label already exists on this user, it will be overwritten with the new alias id._ | +| `OneSignal.User.addAliases({ALIAS_LABEL_01: "ALIAS_ID_01", ALIAS_LABEL_02: "ALIAS_ID_02"})` | _Set aliases for the current user. If any alias already exists, it will be overwritten to the new values._ | +| `OneSignal.User.removeAlias("ALIAS_LABEL")` | _Remove an alias from the current user._ | +| `OneSignal.User.removeAliases(["ALIAS_LABEL_01", "ALIAS_LABEL_02"]])` | _Remove aliases from the current user._ | +| `OneSignal.User.addEmail("customer@company.com")` | _Add a new email subscription to the current user._ | +| `OneSignal.User.removeEmail("customer@company.com")` | _Results in a no-op if the specified email does not exist on the user within the SDK, and no request will be made._ | +| `OneSignal.User.addSms("+15558675309")` | _Add a new SMS subscription to the current user._ | +| `OneSignal.User.removeSms("+15558675309")` | _Results in a no-op if the specified phone number does not exist on the user within the SDK, and no request will be made.._ | +| `OneSignal.User.addTag("KEY", "VALUE")` | _Add a tag for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing messages. If the tag key already exists, it will be replaced with the value provided here._ | +| `OneSignal.User.addTags({"KEY_01": "VALUE_01", "KEY_02": "VALUE_02"})` | _Add multiple tags for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing messages. If the tag key already exists, it will be replaced with the value provided here._ | +| `OneSignal.User.removeTag("KEY")` | _Remove the data tag with the provided key from the current user._ | +| `OneSignal.User.removeTags(["KEY_01", "KEY_02"])` | _Remove multiple tags with the provided keys from the current user._ | ## Push Subscription Namespace The Push Subscription namespace is accessible via `OneSignal.User.pushSubscription` and provides access to push subscription-scoped functionality. - -|**React Native** | **Description** | -|------------------------------------------------------------------------------------------------------------------------------------------------| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `await OneSignal.User.PushSubscription.getId()` | *The readonly push subscription ID.* | -| `await OneSignal.User.PushSubscription.getToken()` | *The readonly push token.* | -| `await OneSignal.User.PushSubscription.getOptedIn()` | *Gets a boolean value indicating whether the current user is opted in to push notifications. This returns `true` when the app has notifications permission and `optedOut` is called. ***Note:*** Does not take into account the existence of the subscription ID and push token. This boolean may return `true` but push notifications may still not be received by the user.* | -| `OneSignal.User.PushSubscription.optIn()` | *Call this method to receive push notifications on the device or to resume receiving of push notifications after calling `optOut`. If needed, this method will prompt the user for push notifications permission.* | -| `OneSignal.User.PushSubscription.optOut()` | *If at any point you want the user to stop receiving push notifications on the current device (regardless of system-level permission status), you can call this method to opt out.* | -| `OneSignal.User.PushSubscription.addObserver(observer: (event) => void)`

***See below for usage*** | *The `OSPushSubscriptionObserver.onOSPushSubscriptionChanged` method will be fired on the passed-in object when the push subscription changes. This method returns the current `OSPushSubscriptionState` at the time of adding this observer.* | -| `OneSignal.User.PushSubscription.removeObserver(observer)`

***See below for usage*** | *Remove a push subscription observer that has been previously added.* | +| **React Native** | **Description** | +| --------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `await OneSignal.User.PushSubscription.getId()` | _The readonly push subscription ID._ | +| `await OneSignal.User.PushSubscription.getToken()` | _The readonly push token._ | +| `await OneSignal.User.PushSubscription.getOptedIn()` | \*Gets a boolean value indicating whether the current user is opted in to push notifications. This returns `true` when the app has notifications permission and `optedOut` is called. **_Note:_** Does not take into account the existence of the subscription ID and push token. This boolean may return `true` but push notifications may still not be received by the user.\* | +| `OneSignal.User.PushSubscription.optIn()` | _Call this method to receive push notifications on the device or to resume receiving of push notifications after calling `optOut`. If needed, this method will prompt the user for push notifications permission._ | +| `OneSignal.User.PushSubscription.optOut()` | _If at any point you want the user to stop receiving push notifications on the current device (regardless of system-level permission status), you can call this method to opt out._ | +| `OneSignal.User.PushSubscription.addObserver(observer: (event) => void)`

**_See below for usage_** | _The `OSPushSubscriptionObserver.onOSPushSubscriptionChanged` method will be fired on the passed-in object when the push subscription changes. This method returns the current `OSPushSubscriptionState` at the time of adding this observer._ | +| `OneSignal.User.PushSubscription.removeObserver(observer)`

**_See below for usage_** | _Remove a push subscription observer that has been previously added._ | ### Push Subscription Observer Any object implementing the `OSPushSubscriptionObserver` protocol can be added as an observer. You can call `removeObserver` to remove any existing listeners. - ```typescript // Create an observer -OneSignal.User.PushSubscription.addObserver(subscription => { +OneSignal.User.PushSubscription.addObserver((subscription) => { console.log('OneSignal: subscription changed: ', subscription); }); @@ -229,48 +226,46 @@ OneSignal.User.PushSubscription.removeObserver(subscription); The Session namespace is accessible via `OneSignal.Session` and provides access to session-scoped functionality. - -|**React Native** | **Description** | -| --------------------------------------------------------- | ---------------------------------------------------------------------------------------- | -| `OneSignal.Session.addOutcome("OUTCOME_NAME")` | *Add an outcome with the provided name, captured against the current session.* | -| `OneSignal.Session.addUniqueOutcome("OUTCOME_NAME")` | *Add a unique outcome with the provided name, captured against the current session.* | -| `OneSignal.Session.addOutcomeWithValue("OUTCOME_NAME", 1)` | *Add an outcome with the provided name and value, captured against the current session.* | - - +| **React Native** | **Description** | +| ---------------------------------------------------------- | ---------------------------------------------------------------------------------------- | +| `OneSignal.Session.addOutcome("OUTCOME_NAME")` | _Add an outcome with the provided name, captured against the current session._ | +| `OneSignal.Session.addUniqueOutcome("OUTCOME_NAME")` | _Add a unique outcome with the provided name, captured against the current session._ | +| `OneSignal.Session.addOutcomeWithValue("OUTCOME_NAME", 1)` | _Add an outcome with the provided name and value, captured against the current session._ | ## Notifications Namespace The Notifications namespace is accessible via `OneSignal.Notifications` and provides access to notification-scoped functionality. -|**React Native** | **Description** | -|----------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------| -| `await OneSignal.Notifications.hasPermission()` | *Whether this app has push notification permission.* | -| `await OneSignal.Notifications.canRequestPermission()` | *Whether attempting to request notification permission will show a prompt. Returns `true` if the device has not been prompted for push notification permission already.* | `await OneSignal.Notifications.permissionNative()` | *(ios only) Returns the enum for the native permission of the device. It will be one of: NotDetermined, Denied, Authorized, Provisional (only available in iOS 12), Ephemeral (only available in iOS 14) * | -| `OneSignal.Notifications.clearAll();` | *Removes all OneSignal notifications.*| -| `OneSignal.Notifications.removeNotification("NOTIFICATION_ID")` | *(Android only) Cancels a single OneSignal notification based on its Android notification integer ID. Use instead of Android's [android.app.NotificationManager.cancel], otherwise the notification will be restored when your app is restarted.*| -| `OneSignal.Notifications.removeGroupedNotifications("GROUP_KEY")` | *(Android only) Cancels a group of OneSignal notifications with the provided group key. Grouping notifications is a OneSignal concept, there is no [android.app.NotificationManager] equivalent.*| -| `OneSignal.Notifications.requestPermission()`

***See below for usage*** | *Prompt the user for permission to receive push notifications. This will display the native system prompt to request push notification permission.* | -| `OneSignal.Notifications.registerForProvisionalAuthorization()` | *(iOS only) Instead of having to prompt the user for permission to send them push notifications, your app can request provisional authorization.*| -| `OneSignal.Notifications.addPermissionObserver(observer)`

***See below for usage*** | *This method will fire when a notification permission setting changes. This happens when the user enables or disables notifications for your app from the system settings outside of your app.*| -| `OneSignal.Notifications.removePermissionObserver(observer)`

***See below for usage*** | *Remove a push permission observer that has been previously added.*| -| `OneSignal.Notifications.addEventListener("foregroundWillDisplay", (event) => {};)`

***See below for usage*** | *Sets the handler to run before displaying a notification while the app is in focus. Use this handler to read notification data and change it or decide if the notification ***should*** show or not.

***Note:*** this runs ***after*** the [Notification Service Extension](https://documentation.onesignal.com/docs/service-extensions) which can be used to modify the notification before showing it.* | -| `OneSignal.Notifications.addEventListener("click", (event) => {};)`

***See below for usage*** | *Sets a handler that will run whenever a notification is opened by the user.*| - +| **React Native** | **Description** | +| -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `await OneSignal.Notifications.hasPermission()` | _Whether this app has push notification permission._ | +| `await OneSignal.Notifications.canRequestPermission()` | _Whether attempting to request notification permission will show a prompt. Returns `true` if the device has not been prompted for push notification permission already._ | `await OneSignal.Notifications.permissionNative()` | _(ios only) Returns the enum for the native permission of the device. It will be one of: NotDetermined, Denied, Authorized, Provisional (only available in iOS 12), Ephemeral (only available in iOS 14) _ | +| `OneSignal.Notifications.clearAll();` | _Removes all OneSignal notifications._ | +| `OneSignal.Notifications.removeNotification("NOTIFICATION_ID")` | _(Android only) Cancels a single OneSignal notification based on its Android notification integer ID. Use instead of Android's [android.app.NotificationManager.cancel], otherwise the notification will be restored when your app is restarted._ | +| `OneSignal.Notifications.removeGroupedNotifications("GROUP_KEY")` | _(Android only) Cancels a group of OneSignal notifications with the provided group key. Grouping notifications is a OneSignal concept, there is no [android.app.NotificationManager] equivalent._ | +| `OneSignal.Notifications.requestPermission()`

**_See below for usage_** | _Prompt the user for permission to receive push notifications. This will display the native system prompt to request push notification permission._ | +| `OneSignal.Notifications.registerForProvisionalAuthorization()` | _(iOS only) Instead of having to prompt the user for permission to send them push notifications, your app can request provisional authorization._ | +| `OneSignal.Notifications.addPermissionObserver(observer)`

**_See below for usage_** | _This method will fire when a notification permission setting changes. This happens when the user enables or disables notifications for your app from the system settings outside of your app._ | +| `OneSignal.Notifications.removePermissionObserver(observer)`

**_See below for usage_** | _Remove a push permission observer that has been previously added._ | +| `OneSignal.Notifications.addEventListener("foregroundWillDisplay", (event) => {};)`

**_See below for usage_** | \*Sets the handler to run before displaying a notification while the app is in focus. Use this handler to read notification data and change it or decide if the notification **_should_** show or not.

**_Note:_** this runs **_after_** the [Notification Service Extension](https://documentation.onesignal.com/docs/service-extensions) which can be used to modify the notification before showing it.\* | +| `OneSignal.Notifications.addEventListener("click", (event) => {};)`

**_See below for usage_** | _Sets a handler that will run whenever a notification is opened by the user._ | ### Prompt for Push Notification Permission + ```typescript -OneSignal.Notifications.requestPermission(accepted => { - console.log("User accepted notifications: " + accepted); +OneSignal.Notifications.requestPermission((accepted) => { + console.log('User accepted notifications: ' + accepted); }); ``` ### Permission Observer + Add an observer when permission status changes. You can call `removePermissionObserver` to remove any existing listeners. ```typescript // Add an observer -let observer = function(req) { - console.log("OneSignal: permission state changed to: " + (req)); +let observer = function (req) { + console.log('OneSignal: permission state changed to: ' + req); }; OneSignal.Notifications.addPermissionObserver(observer); @@ -279,98 +274,110 @@ OneSignal.Notifications.removePermissionObserver(observer); ``` ### Notification Lifecycle Listener + ```typescript -OneSignal.Notifications.addEventListener("foregroundWillDisplay", (event) => { - event.preventDefault(); - // some async work - - // Use display() to display the notification after some async work - event.getNotification().display(); +OneSignal.Notifications.addEventListener('foregroundWillDisplay', (event) => { + event.preventDefault(); + // some async work + + // Use display() to display the notification after some async work + event.getNotification().display(); }); ``` ### Notification Click Listener + ```typescript -OneSignal.Notifications.addEventListener("click", (event) => { - console.log('OneSignal: notification clicked: ' + event); +OneSignal.Notifications.addEventListener('click', (event) => { + console.log('OneSignal: notification clicked: ' + event); }); ``` ## Location Namespace + The Location namespace is accessible via `OneSignal.Location` and provide access to location-scoped functionality. -|**React Native** | **Description** | -|-------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| -| `await OneSignal.Location.isShared()`

***See below for usage*** | *Whether location is currently shared with OneSignal.*| -| `OneSignal.Location.requestPermission()` | *Use this method to manually prompt the user for location permissions. This allows for geotagging so you send notifications to users based on location.* | +| **React Native** | **Description** | +| ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `await OneSignal.Location.isShared()`

**_See below for usage_** | _Whether location is currently shared with OneSignal._ | +| `OneSignal.Location.requestPermission()` | _Use this method to manually prompt the user for location permissions. This allows for geotagging so you send notifications to users based on location._ | ### isShared method + ```typescript const shared: boolean = await OneSignal.Location.isShared(); -console.log("Location shared: ", shared); +console.log('Location shared: ', shared); ``` ## InAppMessages Namespace + The In App Messages namespace is accessible via `OneSignal.InAppMessages` and provide access to in app messages-scoped functionality. -| | **Description** | -|------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------| -| `await OneSignal.InAppMessages.getPaused()`

***See below for usage***

`OneSignal.InAppMessages.setPaused(true)` | *Whether in-app messaging is currently paused. When set to `true`, no IAM will be presented to the user regardless of whether they qualify for them. When set to `false`, any IAMs the user qualifies for will be presented to the user at the appropriate time.* | -| `OneSignal.InAppMessages.addTrigger("triggerKey", "triggerValue")` | *Add a trigger for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user. See [Triggers](https://documentation.onesignal.com/docs/iam-triggers).

If the trigger key already exists, it will be replaced with the value provided here. Note that triggers are not persisted to the backend. They only exist on the local device and are applicable to the current user.* | -| `OneSignal.InAppMessages.addTriggers({"triggerKey1":"triggerValue", "triggerKey2": "triggerValue"})` | *Add multiple triggers for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user. See [Triggers](https://documentation.onesignal.com/docs/iam-triggers).

If any trigger key already exists, it will be replaced with the value provided here. Note that triggers are not persisted to the backend. They only exist on the local device and are applicable to the current user.* | -| `OneSignal.InAppMessages.removeTrigger("triggerKey")` | *Remove the trigger with the provided key from the current user.* | -| `OneSignal.InAppMessages.removeTriggers(["triggerKey1", "triggerKey2"])` | *Remove multiple triggers from the current user.* | -| `OneSignal.InAppMessages.clearTriggers()` | *Clear all triggers from the current user.* | -| ` OneSignal.InAppMessages.setLifecycleHandler(handlerObject)`

***See below for usage*** | *Set the in-app message lifecycle handler.* | -| `OneSignal.InAppMessages.setClickHandler(handler)`

***See below for usage*** | *Set the in-app message click handler.* | +| | **Description** | +| ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `await OneSignal.InAppMessages.getPaused()`

**_See below for usage_**

`OneSignal.InAppMessages.setPaused(true)` | _Whether in-app messaging is currently paused. When set to `true`, no IAM will be presented to the user regardless of whether they qualify for them. When set to `false`, any IAMs the user qualifies for will be presented to the user at the appropriate time._ | +| `OneSignal.InAppMessages.addTrigger("triggerKey", "triggerValue")` | _Add a trigger for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user. See [Triggers](https://documentation.onesignal.com/docs/iam-triggers).

If the trigger key already exists, it will be replaced with the value provided here. Note that triggers are not persisted to the backend. They only exist on the local device and are applicable to the current user._ | +| `OneSignal.InAppMessages.addTriggers({"triggerKey1":"triggerValue", "triggerKey2": "triggerValue"})` | _Add multiple triggers for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user. See [Triggers](https://documentation.onesignal.com/docs/iam-triggers).

If any trigger key already exists, it will be replaced with the value provided here. Note that triggers are not persisted to the backend. They only exist on the local device and are applicable to the current user._ | +| `OneSignal.InAppMessages.removeTrigger("triggerKey")` | _Remove the trigger with the provided key from the current user._ | +| `OneSignal.InAppMessages.removeTriggers(["triggerKey1", "triggerKey2"])` | _Remove multiple triggers from the current user._ | +| `OneSignal.InAppMessages.clearTriggers()` | _Clear all triggers from the current user._ | +| ` OneSignal.InAppMessages.setLifecycleHandler(handlerObject)`

**_See below for usage_** | _Set the in-app message lifecycle handler._ | +| `OneSignal.InAppMessages.setClickHandler(handler)`

**_See below for usage_** | _Set the in-app message click handler._ | ### In-App Message isPaused method + ```typescript const paused = await OneSignal.InAppMessages.getPaused(); -console.log("IAM paused: ", paused); +console.log('IAM paused: ', paused); ``` ### In-App Message Click Listener + ```typescript -OneSignal.InAppMessages.addEventListener("click", (event) => { +OneSignal.InAppMessages.addEventListener('click', (event) => { console.log('OneSignal IAM clicked: ' + event); }); ``` ### In-App Message Lifecycle Listeners + ```typescript -OneSignal.InAppMessages.addEventListener('willDisplay', (event) =>{ - console.log('OneSignal: will display IAM: ', event); +OneSignal.InAppMessages.addEventListener('willDisplay', (event) => { + console.log('OneSignal: will display IAM: ', event); }); -OneSignal.InAppMessages.addEventListener('didDisplay', (event) =>{ - console.log('OneSignal: did display IAM: ', event); +OneSignal.InAppMessages.addEventListener('didDisplay', (event) => { + console.log('OneSignal: did display IAM: ', event); }); -OneSignal.InAppMessages.addEventListener('willDismiss', (event) =>{ - console.log('OneSignal: will dismiss IAM: ', event); +OneSignal.InAppMessages.addEventListener('willDismiss', (event) => { + console.log('OneSignal: will dismiss IAM: ', event); }); -OneSignal.InAppMessages.addEventListener('didDismiss', (event) =>{ - console.log('OneSignal: did dismiss IAM: ', event); +OneSignal.InAppMessages.addEventListener('didDismiss', (event) => { + console.log('OneSignal: did dismiss IAM: ', event); }); ``` ## Debug Namespace -The Debug namespace is accessible via `OneSignal.Debug` and provide access to debug-scoped functionality. -| **React Native** | **Description** | -| ---------------------------------------------- | ---------------------------------------------------------------------------------- | -| `OneSignal.Debug.setLogLevel(6)` | *Sets the log level the OneSignal SDK should be writing to the Xcode log.* | -| `OneSignal.Debug.setAlertLevel(0)` | *Sets the logging level to show as alert dialogs.* | +The Debug namespace is accessible via `OneSignal.Debug` and provide access to debug-scoped functionality. +| **React Native** | **Description** | +| ---------------------------------- | -------------------------------------------------------------------------- | +| `OneSignal.Debug.setLogLevel(6)` | _Sets the log level the OneSignal SDK should be writing to the Xcode log._ | +| `OneSignal.Debug.setAlertLevel(0)` | _Sets the logging level to show as alert dialogs._ | # Glossary + **device-scoped user** -> An anonymous user with no aliases that cannot be retrieved except through the current device or OneSignal dashboard. On app install, the OneSignal SDK is initialized with a *device-scoped user*. A *device-scoped user* can be upgraded to an identified user by calling `OneSignal.login("USER_EXTERNAL_ID")` to identify the user by the specified external user ID. + +> An anonymous user with no aliases that cannot be retrieved except through the current device or OneSignal dashboard. On app install, the OneSignal SDK is initialized with a _device-scoped user_. A _device-scoped user_ can be upgraded to an identified user by calling `OneSignal.login("USER_EXTERNAL_ID")` to identify the user by the specified external user ID. # Limitations + **General** + - Recommend using only in development and staging environments for Alpha releases - Aliases will be available in a future release - Outcomes will be available in a future release @@ -378,6 +385,6 @@ The Debug namespace is accessible via `OneSignal.Debug` and provide access to de - Any `User` namespace calls must be invoked **after** initialization. Example: `OneSignal.User.addTag("tag", "2")` # Known issues + - Identity Verification - - We will be introducing JWT in a follow-up Beta release - \ No newline at end of file + - We will be introducing JWT in a follow-up Beta release diff --git a/README.md b/README.md index 83694efb..8afe8682 100755 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@

### React Native OneSignal SDK + [![npm version](https://img.shields.io/npm/v/react-native-onesignal.svg)](https://www.npmjs.com/package/react-native-onesignal) [![npm downloads](https://img.shields.io/npm/dm/react-native-onesignal.svg)](https://www.npmjs.com/package/react-native-onesignal) --- @@ -10,15 +11,18 @@ [OneSignal](https://onesignal.com/) is a free email, sms, push notification, and in-app message service for mobile apps. This SDK makes it easy to integrate your native React-Native iOS and/or Android apps with OneSignal. #### Installation + See the [Setup Guide](https://documentation.onesignal.com/docs/react-native-sdk-setup) for setup instructions. #### Change Log + See this repository's [release tags](https://github.com/OneSignal/react-native-onesignal/releases) for a complete change log of every released version. #### Support + Please visit this repository's [Github issue tracker](https://github.com/OneSignal/react-native-onesignal/issues) for feature requests and bug reports related specifically to the SDK. For account issues and support please contact OneSignal support from the [OneSignal.com](https://onesignal.com) dashboard. #### Demo Project -To make things easier, we have published demo projects in the `/examples` folder of this repository. +To make things easier, we have published demo projects in the `/examples` folder of this repository. diff --git a/examples/RNOneSignalTS/.watchmanconfig b/examples/RNOneSignalTS/.watchmanconfig index 9e26dfee..0967ef42 100644 --- a/examples/RNOneSignalTS/.watchmanconfig +++ b/examples/RNOneSignalTS/.watchmanconfig @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/examples/RNOneSignalTS/app.json b/examples/RNOneSignalTS/app.json index 078c507b..2fc9ba3f 100644 --- a/examples/RNOneSignalTS/app.json +++ b/examples/RNOneSignalTS/app.json @@ -1,4 +1,4 @@ { "name": "RNOneSignalTS", "displayName": "RNOneSignalTS" -} \ No newline at end of file +} diff --git a/examples/RNOneSignalTS/ios/RNOneSignalTS/Images.xcassets/AppIcon.appiconset/Contents.json b/examples/RNOneSignalTS/ios/RNOneSignalTS/Images.xcassets/AppIcon.appiconset/Contents.json index 118c98f7..48e64ae8 100644 --- a/examples/RNOneSignalTS/ios/RNOneSignalTS/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/examples/RNOneSignalTS/ios/RNOneSignalTS/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,38 +1,38 @@ { - "images" : [ + "images": [ { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "2x" + "idiom": "iphone", + "size": "29x29", + "scale": "2x" }, { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "3x" + "idiom": "iphone", + "size": "29x29", + "scale": "3x" }, { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "2x" + "idiom": "iphone", + "size": "40x40", + "scale": "2x" }, { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "3x" + "idiom": "iphone", + "size": "40x40", + "scale": "3x" }, { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "2x" + "idiom": "iphone", + "size": "60x60", + "scale": "2x" }, { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "3x" + "idiom": "iphone", + "size": "60x60", + "scale": "3x" } ], - "info" : { - "version" : 1, - "author" : "xcode" + "info": { + "version": 1, + "author": "xcode" } -} \ No newline at end of file +} diff --git a/examples/RNOneSignalTS/ios/RNOneSignalTS/Images.xcassets/Contents.json b/examples/RNOneSignalTS/ios/RNOneSignalTS/Images.xcassets/Contents.json index 2d92bd53..97a8662e 100644 --- a/examples/RNOneSignalTS/ios/RNOneSignalTS/Images.xcassets/Contents.json +++ b/examples/RNOneSignalTS/ios/RNOneSignalTS/Images.xcassets/Contents.json @@ -1,6 +1,6 @@ { - "info" : { - "version" : 1, - "author" : "xcode" + "info": { + "version": 1, + "author": "xcode" } } diff --git a/examples/RNOneSignalTS/src/App.tsx b/examples/RNOneSignalTS/src/App.tsx index a94bc0cc..d4d8beea 100644 --- a/examples/RNOneSignalTS/src/App.tsx +++ b/examples/RNOneSignalTS/src/App.tsx @@ -27,7 +27,7 @@ const App = () => { <> - + ); @@ -38,7 +38,7 @@ const styles = StyleSheet.create({ flex: 1, backgroundColor: Colors.white, padding: 10, - } + }, }); export default App; diff --git a/examples/RNOneSignalTS/src/Helpers.tsx b/examples/RNOneSignalTS/src/Helpers.tsx index 048303da..43406953 100644 --- a/examples/RNOneSignalTS/src/Helpers.tsx +++ b/examples/RNOneSignalTS/src/Helpers.tsx @@ -1,63 +1,72 @@ import * as React from 'react'; -import {View, StyleSheet, Platform, KeyboardAvoidingView, TextInput} from "react-native"; -import {Button} from "@react-native-material/core"; +import { + View, + StyleSheet, + Platform, + KeyboardAvoidingView, + TextInput, +} from 'react-native'; +import {Button} from '@react-native-material/core'; const disabledColor = '#BEBEBE'; export const renderButtonView = (name: string, callback: Function) => { - return ( - -