Skip to content

Commit

Permalink
Merge pull request #366 from Countly/staging-np
Browse files Browse the repository at this point in the history
Staging np
  • Loading branch information
turtledreams authored Jul 23, 2024
2 parents a0f571c + e33f5a5 commit 07e8fb3
Show file tree
Hide file tree
Showing 27 changed files with 97 additions and 493 deletions.
29 changes: 22 additions & 7 deletions Countly.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ interface ResultObject {
}
interface ErrorObject { error: string | null }

declare module "countly-sdk-react-native-bridge" {
import type CountlyConfig from "countly-sdk-react-native-bridge/CountlyConfig";
declare module "countly-sdk-react-native-bridge-np" {
import type CountlyConfig from "countly-sdk-react-native-bridge-np/CountlyConfig";

namespace Countly {
string;
Expand Down Expand Up @@ -244,7 +244,7 @@ declare module "countly-sdk-react-native-bridge" {
export function disablePushNotifications(): string | void;

/**
* @deprecated in 23.02.0 : use 'countlyConfig.pushTokenType' instead of 'pushTokenType'.
* @deprecated in 23.02.0 : use 'countlyConfig.pushTokenType' instead of 'pushTokenType'. FOR PUSH VERSION ONLY
*
* @param {string} tokenType - Token type
* @param {string} channelName - Channel name
Expand All @@ -257,6 +257,7 @@ declare module "countly-sdk-react-native-bridge" {
export function pushTokenType(tokenType: string, channelName: string, channelDescription: string): Promise<string> | string;

/**
* @deprecated FOR PUSH VERSION ONLY
*
* Send push token
* @param {object} options - object containing the push token
Expand All @@ -267,6 +268,8 @@ declare module "countly-sdk-react-native-bridge" {
export function sendPushToken(options: { readonly token?: string }): void;

/**
* @deprecated FOR PUSH VERSION ONLY
*
* This method will ask for permission, enables push notification and send push token to countly server.
*
* @param {string} customSoundPath - name of custom sound for push notifications (Only for Android)
Expand All @@ -278,6 +281,7 @@ declare module "countly-sdk-react-native-bridge" {
export function askForNotificationPermission(customSoundPath?: string): string | void;

/**
* @deprecated FOR PUSH VERSION ONLY
*
* Set callback to receive push notifications
* @param {callback listener } theListener
Expand All @@ -286,7 +290,7 @@ declare module "countly-sdk-react-native-bridge" {
export function registerForNotification(theListener: (theNotification: string) => void): any; // The return type should be adjusted to the actual event subscription type

/**
* @deprecated in 23.02.0 : use 'countlyConfig.configureIntentRedirectionCheck' instead of 'configureIntentRedirectionCheck'.
* @deprecated in 23.02.0 : use 'countlyConfig.configureIntentRedirectionCheck' instead of 'configureIntentRedirectionCheck'. FOR PUSH VERSION ONLY
*
* Configure intent redirection checks for push notification
* Should be called before Countly "askForNotificationPermission"
Expand Down Expand Up @@ -1096,7 +1100,7 @@ declare module "countly-sdk-react-native-bridge" {
export default Countly;
}

declare module "countly-sdk-react-native-bridge/CountlyConfig" {
declare module "countly-sdk-react-native-bridge-np/CountlyConfig" {
/**
*
* This class holds APM specific configurations to be used with
Expand Down Expand Up @@ -1195,7 +1199,7 @@ declare module "countly-sdk-react-native-bridge/CountlyConfig" {
* Method to give consent for specific features before init
*
* @param {string[]} consents consents e.g ['location', 'sessions',
* 'attribution', 'push', 'events', 'views', 'crashes', 'users', 'push',
* 'attribution', 'push', 'events', 'views', 'crashes', 'users',
* 'star-rating', 'apm', 'feedback', 'remote-config']
*/
giveConsent(consents: readonly string[]): CountlyConfig;
Expand Down Expand Up @@ -1227,14 +1231,17 @@ declare module "countly-sdk-react-native-bridge/CountlyConfig" {
enableApm(): CountlyConfig;

/**
* @deprecated FOR PUSH VERSION ONLY
*
* AdditionalIntentRedirectionChecks are enabled by default.
* This method should be used to disable them.
*/
disableAdditionalIntentRedirectionChecks(): CountlyConfig;

/**
* Method to set the push token type
* @deprecated
* @deprecated FOR PUSH VERSION ONLY
*
* Use setPushTokenType() instead to set pushToken
* Use setPushNotificationChannelInformation() instead to set channel information
*
Expand All @@ -1245,6 +1252,8 @@ declare module "countly-sdk-react-native-bridge/CountlyConfig" {
pushTokenType(tokenType: TokenType, channelName: string, channelDescription: string): CountlyConfig;

/**
* @deprecated FOR PUSH VERSION ONLY
*
* Method to set the push token type
* NB: ONLY FOR iOS
*
Expand All @@ -1254,6 +1263,8 @@ declare module "countly-sdk-react-native-bridge/CountlyConfig" {
setPushTokenType(tokenType: messagingMode): CountlyConfig;

/**
* @deprecated FOR PUSH VERSION ONLY
*
* Method to set the push channel name and description
* NB: ONLY FOR ANDROID
*
Expand All @@ -1263,6 +1274,8 @@ declare module "countly-sdk-react-native-bridge/CountlyConfig" {
setPushNotificationChannelInformation(name: string, description: string): CountlyConfig;

/**
* @deprecated FOR PUSH VERSION ONLY
*
* Method to set the push notification accent color
* NB: ONLY FOR ANDROID
*
Expand All @@ -1272,6 +1285,8 @@ declare module "countly-sdk-react-native-bridge/CountlyConfig" {
setPushNotificationAccentColor(accentColor: string): CountlyConfig;

/**
* @deprecated FOR PUSH VERSION ONLY
*
* Method to configure intent redirection check
*
* @param {string[]} allowedIntentClassNames allowed intent class names
Expand Down
27 changes: 25 additions & 2 deletions Countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Countly.userDataBulk = {}; // userDataBulk interface

let _isPushInitialized = false;

const BUILDING_WITH_PUSH_DISABLED = true;
const _pushDisabledMsg = 'Push Notifications are disabled in this flavor. Please use the original Countly React Native SDK if you need to use Push Notifications.';

/*
* Listener for rating widget callback, when callback recieve we will remove the callback using listener.
*/
Expand Down Expand Up @@ -218,6 +221,10 @@ Countly.disablePushNotifications = function () {
* @return {string | void} error message or void
*/
Countly.pushTokenType = function (tokenType, channelName, channelDescription) {
if (BUILDING_WITH_PUSH_DISABLED) {
L.w(`pushTokenType, ${_pushDisabledMsg}`);
return _pushDisabledMsg;
}
const message = Validate.String(tokenType, "tokenType", "pushTokenType");
if (message) {
return message;
Expand All @@ -239,6 +246,10 @@ Countly.pushTokenType = function (tokenType, channelName, channelDescription) {
* @return {string | void} error message or void
*/
Countly.sendPushToken = function (options) {
if (BUILDING_WITH_PUSH_DISABLED) {
L.w(`sendPushToken, ${_pushDisabledMsg}`);
return;
}
L.d(`sendPushToken, Sending push token: [${JSON.stringify(options)}]`);
const args = [];
args.push(options.token || "");
Expand All @@ -255,6 +266,10 @@ Countly.sendPushToken = function (options) {
* @return {string | void} error message or void
*/
Countly.askForNotificationPermission = function (customSoundPath = "null") {
if (BUILDING_WITH_PUSH_DISABLED) {
L.w(`askForNotificationPermission, ${_pushDisabledMsg}`);
return _pushDisabledMsg;
}
if (!_state.isInitialized) {
const message = "'init' must be called before 'askForNotificationPermission'";
L.e(`askForNotificationPermission, ${message}`);
Expand All @@ -272,6 +287,10 @@ Countly.askForNotificationPermission = function (customSoundPath = "null") {
* @return {NativeEventEmitter} event
*/
Countly.registerForNotification = function (theListener) {
if (BUILDING_WITH_PUSH_DISABLED) {
L.w(`registerForNotification, ${_pushDisabledMsg}`);
return;
}
L.d("registerForNotification, Registering for notification");
const event = eventEmitter.addListener(pushNotificationCallbackName, theListener);
CountlyReactNative.registerForNotification([]);
Expand All @@ -290,15 +309,19 @@ Countly.registerForNotification = function (theListener) {
* @return {string | void} error message or void
*/
Countly.configureIntentRedirectionCheck = function (allowedIntentClassNames = [], allowedIntentPackageNames = [], useAdditionalIntentRedirectionChecks = true) {
if (BUILDING_WITH_PUSH_DISABLED) {
L.w(`configureIntentRedirectionCheck, ${_pushDisabledMsg}`);
return;
}
if (/ios/.exec(Platform.OS)) {
L.e("configureIntentRedirectionCheck, configureIntentRedirectionCheck is not required for iOS");
L.w("configureIntentRedirectionCheck, configureIntentRedirectionCheck is not required for iOS");

return "configureIntentRedirectionCheck : not required for iOS";
}

if (_isPushInitialized) {
let message = "'configureIntentRedirectionCheck' must be called before 'askForNotificationPermission'";
L.e(`configureIntentRedirectionCheck, ${message}`);
L.w(`configureIntentRedirectionCheck, ${message}`);
return message;
}
L.w("configureIntentRedirectionCheck, configureIntentRedirectionCheck is deprecated, use countlyConfig.configureIntentRedirectionCheck instead");
Expand Down
24 changes: 22 additions & 2 deletions CountlyConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { initialize } from "./Logger.js";
import CountlyConfigApm from "./lib/configuration_interfaces/countly_config_apm.js";

const BUILDING_WITH_PUSH_DISABLED = true;

/**
* Countly SDK React Native Bridge
* https://github.com/Countly/countly-sdk-react-native-bridge
Expand All @@ -8,7 +11,6 @@ import CountlyConfigApm from "./lib/configuration_interfaces/countly_config_apm.
/**
*
* Config Object for Countly Init
* Should be called before Countly "askForNotificationPermission"
*
* @param {String} serverURL server url
* @param {String} appKey application key
Expand Down Expand Up @@ -94,7 +96,7 @@ class CountlyConfig {
* Method to give consent for specific features before init
*
* @param {String[]} consents consents e.g ['location', 'sessions',
* 'attribution', 'push', 'events', 'views', 'crashes', 'users', 'push',
* 'attribution', 'events', 'views', 'crashes', 'users',
* 'star-rating', 'apm', 'feedback', 'remote-config']
*/
giveConsent(consents) {
Expand Down Expand Up @@ -145,6 +147,9 @@ class CountlyConfig {
* This method should be used to disable them.
*/
disableAdditionalIntentRedirectionChecks() {
if (BUILDING_WITH_PUSH_DISABLED) {
return this;
}
this.disableAdditionalIntentRedirectionChecks = true;
return this;
}
Expand All @@ -160,6 +165,9 @@ class CountlyConfig {
* @param {String} channelDescription channel description
*/
pushTokenType(tokenType, channelName, channelDescription) {
if (BUILDING_WITH_PUSH_DISABLED) {
return this;
}
this.tokenType = tokenType;
this.channelName = channelName;
this.channelDescription = channelDescription;
Expand All @@ -174,6 +182,9 @@ class CountlyConfig {
* Possible values include 'DEVELOPMENT', 'PRODUCTION', 'ADHOC'.
*/
setPushTokenType(tokenType) {
if (BUILDING_WITH_PUSH_DISABLED) {
return this;
}
this.tokenType = tokenType;
return this;
}
Expand All @@ -186,6 +197,9 @@ class CountlyConfig {
* @param {String} description channel description
*/
setPushNotificationChannelInformation(name, description) {
if (BUILDING_WITH_PUSH_DISABLED) {
return this;
}
this.channelName = name;
this.channelDescription = description;
return this;
Expand All @@ -199,6 +213,9 @@ class CountlyConfig {
* example '#000000'
*/
setPushNotificationAccentColor(accentColor) {
if (BUILDING_WITH_PUSH_DISABLED) {
return this;
}
this.accentColor = accentColor;
return this;
}
Expand All @@ -210,6 +227,9 @@ class CountlyConfig {
* @param {String[]} allowedIntentPackageNames allowed intent package name
*/
configureIntentRedirectionCheck(allowedIntentClassNames, allowedIntentPackageNames) {
if (BUILDING_WITH_PUSH_DISABLED) {
return this;
}
this.allowedIntentClassNames = allowedIntentClassNames;
this.allowedIntentPackageNames = allowedIntentPackageNames;
return this;
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/2d691b48780b440d915a0cfa059474b1)](https://app.codacy.com/gh/Countly/countly-sdk-react-native-bridge?utm_source=github.com&utm_medium=referral&utm_content=Countly/countly-sdk-react-native-bridge&utm_campaign=Badge_Grade)

# Countly React Native Bridge SDK
# Countly React Native Bridge SDK - No Push
This repository contains the Countly React Native Bridge SDK, which can be integrated into React Native mobile applications. The Countly React Native Bridge SDK is intended to be used with [Countly Lite](https://countly.com/lite) or [Countly Enterprise](https://count.ly/product).

## What is Countly?
Expand All @@ -25,7 +25,6 @@ For an example integration of this SDK, you can have a look [here](https://githu

This SDK supports the following features:
* [Analytics](https://support.count.ly/hc/en-us/articles/4431589003545-Analytics)
* [Push Notifications](https://support.count.ly/hc/en-us/articles/4405405459225-Push-Notifications)
* [User Profiles](https://support.count.ly/hc/en-us/articles/4403281285913-User-Profiles)
* [Crash Reports](https://support.count.ly/hc/en-us/articles/4404213566105-Crashes-Errors)
* [A/B Testing](https://support.count.ly/hc/en-us/articles/4416496362393-A-B-Testing-)
Expand Down
5 changes: 0 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,4 @@ repositories {
dependencies {
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
implementation 'ly.count.android:sdk:24.4.0'

// Import the BoM for the Firebase platform
// The BoM version of 28.4.2 is the newest release that will target firebase-messaging version 22
implementation platform('com.google.firebase:firebase-bom:28.4.2')
implementation "com.google.firebase:firebase-messaging"
}
13 changes: 1 addition & 12 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ly.count.android.sdk.react">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="${applicationId}.CountlyPush.BROADCAST_PERMISSION" />
<uses-permission android:name="android.permission.BROADCAST_CLOSE_SYSTEM_DIALOGS" android:maxSdkVersion="30" />
<permission android:name="${applicationId}.CountlyPush.BROADCAST_PERMISSION"
android:protectionLevel="signature" />
<application>
<uses-library android:name="android.test.runner"/>
<service android:name="ly.count.android.sdk.react.CountlyMessagingService" android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>

</manifest>
</manifest>
Loading

0 comments on commit 07e8fb3

Please sign in to comment.