react-native-onesignal
Advanced tools
Comparing version 4.4.1 to 4.5.0
@@ -64,3 +64,5 @@ "use strict"; | ||
var handlerArray = this.eventHandlerArrayMap.get(eventName); | ||
handlerArray && handlerArray.length > 0 ? handlerArray.push(handler) : this.eventHandlerArrayMap.set(eventName, [handler]); | ||
handlerArray && handlerArray.length > 0 | ||
? handlerArray.push(handler) | ||
: this.eventHandlerArrayMap.set(eventName, [handler]); | ||
}; | ||
@@ -79,3 +81,3 @@ /** | ||
var addListenerCallback = function (payload) { | ||
if ((0, helpers_1.isMultipleInstancesPossible)(eventName)) { | ||
if (helpers_1.isMultipleInstancesPossible(eventName)) { | ||
// used for adders | ||
@@ -82,0 +84,0 @@ var handlerArray = _this.eventHandlerArrayMap.get(eventName); |
@@ -10,3 +10,3 @@ "use strict"; | ||
function isValidCallback(handler) { | ||
(0, invariant_1.default)(typeof handler === 'function', 'Must provide a valid callback'); | ||
invariant_1.default(typeof handler === 'function', 'Must provide a valid callback'); | ||
} | ||
@@ -16,3 +16,3 @@ exports.isValidCallback = isValidCallback; | ||
if (module == null) { | ||
console.error("Could not load RNOneSignal native module. Make sure native dependencies are properly linked."); | ||
console.error('Could not load RNOneSignal native module. Make sure native dependencies are properly linked.'); | ||
return false; | ||
@@ -19,0 +19,0 @@ } |
@@ -107,2 +107,17 @@ import { DeviceState, ChangeEvent, PermissionChange, SubscriptionChange, EmailSubscriptionChange, SMSSubscriptionChange } from './models/Subscription'; | ||
/** | ||
* Associates a temporary push token with an Activity ID on the OneSignal server. | ||
* @param {string} activityId | ||
* @param {string} token | ||
* @param {Function} handler | ||
* @returns void | ||
*/ | ||
static enterLiveActivity(activityId: string, token: string, handler?: Function): void; | ||
/** | ||
* Deletes activityId associated temporary push token on the OneSignal server. | ||
* @param {string} activityId | ||
* @param {Function} handler | ||
* @returns void | ||
*/ | ||
static exitLiveActivity(activityId: string, handler?: Function): void; | ||
/** | ||
* True if the application has location share activated, false otherwise | ||
@@ -355,3 +370,3 @@ * @returns Promise<boolean> | ||
export { default as OSNotification } from './OSNotification'; | ||
export { OpenedEventAction, OpenedEventActionType } from './models/NotificationEvents'; | ||
export { IosPermissionStatus, ObserverChangeEvent } from './models/Subscription'; | ||
export { OpenedEventAction, OpenedEventActionType, } from './models/NotificationEvents'; | ||
export { IosPermissionStatus, ObserverChangeEvent, } from './models/Subscription'; |
@@ -42,3 +42,3 @@ 'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OSNotification = exports.NotificationReceivedEvent = void 0; | ||
exports.NotificationReceivedEvent = void 0; | ||
var react_native_1 = require("react-native"); | ||
@@ -62,4 +62,5 @@ var EventManager_1 = __importDefault(require("./events/EventManager")); | ||
OneSignal.setAppId = function (appId) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.setAppId(appId); | ||
@@ -74,5 +75,6 @@ }; | ||
OneSignal.addPermissionObserver = function (observer) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
(0, helpers_1.isValidCallback)(observer); | ||
} | ||
helpers_1.isValidCallback(observer); | ||
RNOneSignal.addPermissionObserver(); | ||
@@ -86,4 +88,5 @@ eventManager.addEventHandler(events_1.PERMISSION_CHANGED, observer); | ||
OneSignal.clearPermissionObservers = function () { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.removePermissionObserver(); | ||
@@ -98,5 +101,6 @@ eventManager.clearEventHandler(events_1.PERMISSION_CHANGED); | ||
OneSignal.addSubscriptionObserver = function (observer) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
(0, helpers_1.isValidCallback)(observer); | ||
} | ||
helpers_1.isValidCallback(observer); | ||
RNOneSignal.addSubscriptionObserver(); | ||
@@ -110,4 +114,5 @@ eventManager.addEventHandler(events_1.SUBSCRIPTION_CHANGED, observer); | ||
OneSignal.clearSubscriptionObservers = function () { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.removeSubscriptionObserver(); | ||
@@ -122,5 +127,6 @@ eventManager.clearEventHandler(events_1.SUBSCRIPTION_CHANGED); | ||
OneSignal.addEmailSubscriptionObserver = function (observer) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
(0, helpers_1.isValidCallback)(observer); | ||
} | ||
helpers_1.isValidCallback(observer); | ||
RNOneSignal.addEmailSubscriptionObserver(); | ||
@@ -134,4 +140,5 @@ eventManager.addEventHandler(events_1.EMAIL_SUBSCRIPTION_CHANGED, observer); | ||
OneSignal.clearEmailSubscriptionObservers = function () { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.removeEmailSubscriptionObserver(); | ||
@@ -146,5 +153,6 @@ eventManager.clearEventHandler(events_1.EMAIL_SUBSCRIPTION_CHANGED); | ||
OneSignal.addSMSSubscriptionObserver = function (observer) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
(0, helpers_1.isValidCallback)(observer); | ||
} | ||
helpers_1.isValidCallback(observer); | ||
RNOneSignal.addSMSSubscriptionObserver(); | ||
@@ -158,4 +166,5 @@ eventManager.addEventHandler(events_1.SMS_SUBSCRIPTION_CHANGED, observer); | ||
OneSignal.clearSMSSubscriptionObservers = function () { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.removeSMSSubscriptionObserver(); | ||
@@ -173,5 +182,6 @@ eventManager.clearEventHandler(events_1.SMS_SUBSCRIPTION_CHANGED); | ||
OneSignal.setNotificationWillShowInForegroundHandler = function (handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
(0, helpers_1.isValidCallback)(handler); | ||
} | ||
helpers_1.isValidCallback(handler); | ||
RNOneSignal.setNotificationWillShowInForegroundHandler(); | ||
@@ -186,5 +196,6 @@ eventManager.setEventHandler(events_1.NOTIFICATION_WILL_SHOW, handler); | ||
OneSignal.setNotificationOpenedHandler = function (handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
(0, helpers_1.isValidCallback)(handler); | ||
} | ||
helpers_1.isValidCallback(handler); | ||
RNOneSignal.setNotificationOpenedHandler(); | ||
@@ -206,10 +217,11 @@ eventManager.setEventHandler(events_1.NOTIFICATION_OPENED, handler); | ||
OneSignal.promptForPushNotificationsWithUserResponse = function (fallbackToSettingsOrHandler, handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
var fallbackToSettings = false; | ||
if (typeof fallbackToSettingsOrHandler === "function") { | ||
if (typeof fallbackToSettingsOrHandler === 'function') { | ||
// Method was called like promptForPushNotificationsWithUserResponse(handler: function) | ||
handler = fallbackToSettingsOrHandler; | ||
} | ||
else if (typeof fallbackToSettingsOrHandler === "boolean") { | ||
else if (typeof fallbackToSettingsOrHandler === 'boolean') { | ||
// Method was called like promptForPushNotificationsWithUserResponse(fallbackToSettings: boolean, handler?: function) | ||
@@ -234,10 +246,11 @@ fallbackToSettings = fallbackToSettingsOrHandler; | ||
OneSignal.registerForProvisionalAuthorization = function (handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (react_native_1.Platform.OS === 'ios') { | ||
(0, helpers_1.isValidCallback)(handler); | ||
helpers_1.isValidCallback(handler); | ||
RNOneSignal.registerForProvisionalAuthorization(handler); | ||
} | ||
else { | ||
console.log("registerForProvisionalAuthorization: this function is not supported on Android"); | ||
console.log('registerForProvisionalAuthorization: this function is not supported on Android'); | ||
} | ||
@@ -251,4 +264,5 @@ }; | ||
OneSignal.disablePush = function (disable) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.disablePush(disable); | ||
@@ -262,4 +276,5 @@ }; | ||
OneSignal.unsubscribeWhenNotificationsAreDisabled = function (unsubscribe) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (react_native_1.Platform.OS === 'android') { | ||
@@ -269,5 +284,43 @@ RNOneSignal.unsubscribeWhenNotificationsAreDisabled(unsubscribe); | ||
else { | ||
console.log("unsubscribeWhenNotificationsAreDisabled: this function is not supported on iOS"); | ||
console.log('unsubscribeWhenNotificationsAreDisabled: this function is not supported on iOS'); | ||
} | ||
}; | ||
/* L I V E A C T I V I T Y */ | ||
/** | ||
* Associates a temporary push token with an Activity ID on the OneSignal server. | ||
* @param {string} activityId | ||
* @param {string} token | ||
* @param {Function} handler | ||
* @returns void | ||
*/ | ||
OneSignal.enterLiveActivity = function (activityId, token, handler) { | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (!handler) { | ||
handler = function () { }; | ||
} | ||
// Only Available on iOS | ||
if (react_native_1.Platform.OS === 'ios') { | ||
RNOneSignal.enterLiveActivity(activityId, token, handler); | ||
} | ||
}; | ||
/** | ||
* Deletes activityId associated temporary push token on the OneSignal server. | ||
* @param {string} activityId | ||
* @param {Function} handler | ||
* @returns void | ||
*/ | ||
OneSignal.exitLiveActivity = function (activityId, handler) { | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (!handler) { | ||
handler = function () { }; | ||
} | ||
// Only Available on iOS | ||
if (react_native_1.Platform.OS === 'ios') { | ||
RNOneSignal.exitLiveActivity(activityId, handler); | ||
} | ||
}; | ||
/* L O C A T I O N */ | ||
@@ -280,4 +333,5 @@ /** | ||
// must return a promise | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return Promise.resolve(false); | ||
} | ||
return RNOneSignal.isLocationShared(); | ||
@@ -291,4 +345,5 @@ }; | ||
OneSignal.setLocationShared = function (shared) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.setLocationShared(shared); | ||
@@ -301,4 +356,5 @@ }; | ||
OneSignal.promptLocation = function () { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
//Supported in both iOS & Android | ||
@@ -319,4 +375,5 @@ RNOneSignal.promptLocation(); | ||
case 0: | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return [2 /*return*/, Promise.resolve(null)]; | ||
} | ||
return [4 /*yield*/, RNOneSignal.getDeviceState()]; | ||
@@ -326,4 +383,5 @@ case 1: | ||
if (react_native_1.Platform.OS === 'android') { | ||
deviceState['hasNotificationPermission'] = deviceState['areNotificationsEnabled']; | ||
delete deviceState['areNotificationsEnabled']; | ||
deviceState.hasNotificationPermission = | ||
deviceState.areNotificationsEnabled; | ||
delete deviceState.areNotificationsEnabled; | ||
} | ||
@@ -343,4 +401,5 @@ return [2 /*return*/, deviceState]; | ||
OneSignal.setLanguage = function (language, onSuccess, onFailure) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (!onSuccess) { | ||
@@ -362,7 +421,8 @@ onSuccess = function () { }; | ||
OneSignal.sendTag = function (key, value) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
if (!key || (!value && value !== "")) { | ||
console.error("OneSignal: sendTag: must include a key and a value"); | ||
} | ||
if (!key || (!value && value !== '')) { | ||
console.error('OneSignal: sendTag: must include a key and a value'); | ||
} | ||
RNOneSignal.sendTag(key, value); | ||
@@ -376,4 +436,5 @@ }; | ||
OneSignal.sendTags = function (tags) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
var keys = Object.keys(tags); | ||
@@ -391,4 +452,5 @@ if (keys.length === 0) { | ||
OneSignal.getTags = function (handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.getTags(handler); | ||
@@ -402,7 +464,8 @@ }; | ||
OneSignal.deleteTag = function (key) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
if (typeof key !== "string") { | ||
console.error("OneSignal: deleteTag: key argument must be of type string"); | ||
} | ||
if (typeof key !== 'string') { | ||
console.error('OneSignal: deleteTag: key argument must be of type string'); | ||
} | ||
RNOneSignal.deleteTags([key]); | ||
@@ -415,6 +478,7 @@ }; | ||
OneSignal.deleteTags = function (keys) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (!Array.isArray(keys)) { | ||
console.error("OneSignal: deleteTags: argument must be of array type"); | ||
console.error('OneSignal: deleteTags: argument must be of array type'); | ||
} | ||
@@ -432,9 +496,12 @@ RNOneSignal.deleteTags(keys); | ||
OneSignal.setEmail = function (email, emailAuthCode, handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
if (emailAuthCode === undefined) | ||
} | ||
if (emailAuthCode === undefined) { | ||
emailAuthCode = null; | ||
} | ||
// Android workaround for the current issue of callback fired more than once | ||
if (!handler && react_native_1.Platform.OS === 'ios') | ||
if (!handler && react_native_1.Platform.OS === 'ios') { | ||
handler = function () { }; | ||
} | ||
RNOneSignal.setEmail(email, emailAuthCode, handler); | ||
@@ -447,7 +514,9 @@ }; | ||
OneSignal.logoutEmail = function (handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
// Android workaround for the current issue of callback fired more than once | ||
if (!handler && react_native_1.Platform.OS === 'ios') | ||
if (!handler && react_native_1.Platform.OS === 'ios') { | ||
handler = function () { }; | ||
} | ||
RNOneSignal.logoutEmail(handler); | ||
@@ -464,9 +533,12 @@ }; | ||
OneSignal.setSMSNumber = function (smsNumber, smsAuthCode, handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
if (smsAuthCode === undefined) | ||
} | ||
if (smsAuthCode === undefined) { | ||
smsAuthCode = null; | ||
} | ||
// Android workaround for the current issue of callback fired more than once | ||
if (!handler && react_native_1.Platform.OS === 'ios') | ||
if (!handler && react_native_1.Platform.OS === 'ios') { | ||
handler = function () { }; | ||
} | ||
RNOneSignal.setSMSNumber(smsNumber, smsAuthCode, handler); | ||
@@ -479,7 +551,9 @@ }; | ||
OneSignal.logoutSMSNumber = function (handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
// Android workaround for the current issue of callback fired more than once | ||
if (!handler && react_native_1.Platform.OS === 'ios') | ||
if (!handler && react_native_1.Platform.OS === 'ios') { | ||
handler = function () { }; | ||
} | ||
RNOneSignal.logoutSMSNumber(handler); | ||
@@ -496,8 +570,11 @@ }; | ||
OneSignal.postNotification = function (notificationObjectString, onSuccess, onFailure) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
if (!onSuccess) | ||
} | ||
if (!onSuccess) { | ||
onSuccess = function () { }; | ||
if (!onFailure) | ||
} | ||
if (!onFailure) { | ||
onFailure = function () { }; | ||
} | ||
RNOneSignal.postNotification(notificationObjectString, onSuccess, onFailure); | ||
@@ -510,4 +587,5 @@ }; | ||
OneSignal.clearOneSignalNotifications = function () { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (react_native_1.Platform.OS === 'android') { | ||
@@ -517,3 +595,3 @@ RNOneSignal.clearOneSignalNotifications(); | ||
else { | ||
console.log("clearOneSignalNotifications: this function is not supported on iOS"); | ||
console.log('clearOneSignalNotifications: this function is not supported on iOS'); | ||
} | ||
@@ -528,4 +606,5 @@ }; | ||
OneSignal.removeNotification = function (id) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (react_native_1.Platform.OS === 'android') { | ||
@@ -535,3 +614,3 @@ RNOneSignal.removeNotification(id); | ||
else { | ||
console.log("removeNotification: this function is not supported on iOS"); | ||
console.log('removeNotification: this function is not supported on iOS'); | ||
} | ||
@@ -546,4 +625,5 @@ }; | ||
OneSignal.removeGroupedNotifications = function (id) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (react_native_1.Platform.OS === 'android') { | ||
@@ -553,3 +633,3 @@ RNOneSignal.removeGroupedNotifications(id); | ||
else { | ||
console.log("removeGroupedNotifications: this function is not supported on iOS"); | ||
console.log('removeGroupedNotifications: this function is not supported on iOS'); | ||
} | ||
@@ -563,4 +643,5 @@ }; | ||
OneSignal.setLaunchURLsInApp = function (isEnabled) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (react_native_1.Platform.OS === 'ios') { | ||
@@ -570,3 +651,3 @@ RNOneSignal.setLaunchURLsInApp(isEnabled); | ||
else { | ||
console.log("setLaunchURLsInApp: this function is not supported on Android"); | ||
console.log('setLaunchURLsInApp: this function is not supported on Android'); | ||
} | ||
@@ -583,5 +664,6 @@ }; | ||
OneSignal.setExternalUserId = function (externalId, handlerOrAuth, handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
if (typeof handlerOrAuth === "function") { | ||
} | ||
if (typeof handlerOrAuth === 'function') { | ||
RNOneSignal.setExternalUserId(externalId, null, handlerOrAuth); | ||
@@ -601,7 +683,9 @@ return; | ||
OneSignal.removeExternalUserId = function (handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
// Android workaround for the current issue of callback fired more than once | ||
if (handler === undefined && react_native_1.Platform.OS === 'ios') | ||
if (handler === undefined && react_native_1.Platform.OS === 'ios') { | ||
handler = function () { }; | ||
} | ||
RNOneSignal.removeExternalUserId(handler); | ||
@@ -616,5 +700,6 @@ }; | ||
OneSignal.setInAppMessageClickHandler = function (handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
(0, helpers_1.isValidCallback)(handler); | ||
} | ||
helpers_1.isValidCallback(handler); | ||
RNOneSignal.initInAppMessageClickHandlerParams(); | ||
@@ -630,18 +715,19 @@ RNOneSignal.setInAppMessageClickHandler(); | ||
OneSignal.setInAppMessageLifecycleHandler = function (handlerObject) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (handlerObject.onWillDisplayInAppMessage) { | ||
(0, helpers_1.isValidCallback)(handlerObject.onWillDisplayInAppMessage); | ||
helpers_1.isValidCallback(handlerObject.onWillDisplayInAppMessage); | ||
eventManager.setEventHandler(events_1.IN_APP_MESSAGE_WILL_DISPLAY, handlerObject.onWillDisplayInAppMessage); | ||
} | ||
if (handlerObject.onDidDisplayInAppMessage) { | ||
(0, helpers_1.isValidCallback)(handlerObject.onDidDisplayInAppMessage); | ||
helpers_1.isValidCallback(handlerObject.onDidDisplayInAppMessage); | ||
eventManager.setEventHandler(events_1.IN_APP_MESSAGE_DID_DISPLAY, handlerObject.onDidDisplayInAppMessage); | ||
} | ||
if (handlerObject.onWillDismissInAppMessage) { | ||
(0, helpers_1.isValidCallback)(handlerObject.onWillDismissInAppMessage); | ||
helpers_1.isValidCallback(handlerObject.onWillDismissInAppMessage); | ||
eventManager.setEventHandler(events_1.IN_APP_MESSAGE_WILL_DISMISS, handlerObject.onWillDismissInAppMessage); | ||
} | ||
if (handlerObject.onDidDismissInAppMessage) { | ||
(0, helpers_1.isValidCallback)(handlerObject.onDidDismissInAppMessage); | ||
helpers_1.isValidCallback(handlerObject.onDidDismissInAppMessage); | ||
eventManager.setEventHandler(events_1.IN_APP_MESSAGE_DID_DISMISS, handlerObject.onDidDismissInAppMessage); | ||
@@ -658,7 +744,8 @@ } | ||
OneSignal.addTrigger = function (key, value) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
// value can be assigned to `false` so we cannot just check `!value` | ||
if (!key || value == null) { | ||
console.error("OneSignal: addTrigger: must include a key and a value"); | ||
console.error('OneSignal: addTrigger: must include a key and a value'); | ||
} | ||
@@ -675,4 +762,5 @@ var trigger = {}; | ||
OneSignal.addTriggers = function (triggers) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
var keys = Object.keys(triggers); | ||
@@ -690,4 +778,5 @@ if (keys.length === 0) { | ||
OneSignal.removeTriggersForKeys = function (keys) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.removeTriggersForKeys(keys); | ||
@@ -701,4 +790,5 @@ }; | ||
OneSignal.removeTriggerForKey = function (key) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.removeTriggerForKey(key); | ||
@@ -713,4 +803,5 @@ }; | ||
// must return a promise | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return Promise.resolve(null); | ||
} | ||
return RNOneSignal.getTriggerValueForKey(key); | ||
@@ -724,4 +815,5 @@ }; | ||
OneSignal.pauseInAppMessages = function (pause) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.pauseInAppMessages(pause); | ||
@@ -737,4 +829,5 @@ }; | ||
OneSignal.sendOutcome = function (name, handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (!handler) { | ||
@@ -752,4 +845,5 @@ handler = function () { }; | ||
OneSignal.sendUniqueOutcome = function (name, handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (!handler) { | ||
@@ -769,4 +863,5 @@ handler = function () { }; | ||
OneSignal.sendOutcomeWithValue = function (name, value, handler) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (!handler) { | ||
@@ -783,4 +878,5 @@ handler = function () { }; | ||
OneSignal.userProvidedPrivacyConsent = function () { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return Promise.resolve(false); | ||
} | ||
//returns a promise | ||
@@ -794,4 +890,5 @@ return RNOneSignal.userProvidedPrivacyConsent(); | ||
OneSignal.requiresUserPrivacyConsent = function () { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return Promise.resolve(false); | ||
} | ||
//returns a promise | ||
@@ -806,4 +903,5 @@ return RNOneSignal.requiresUserPrivacyConsent(); | ||
OneSignal.setRequiresUserPrivacyConsent = function (required) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.setRequiresUserPrivacyConsent(required); | ||
@@ -817,4 +915,5 @@ }; | ||
OneSignal.provideUserConsent = function (granted) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.provideUserConsent(granted); | ||
@@ -830,4 +929,5 @@ }; | ||
OneSignal.setLogLevel = function (nsLogLevel, visualLogLevel) { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.setLogLevel(nsLogLevel, visualLogLevel); | ||
@@ -840,4 +940,5 @@ }; | ||
OneSignal.clearHandlers = function () { | ||
if (!(0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) | ||
if (!helpers_1.isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
eventManager.clearHandlers(); | ||
@@ -849,2 +950,2 @@ }; | ||
var OSNotification_1 = require("./OSNotification"); | ||
Object.defineProperty(exports, "OSNotification", { enumerable: true, get: function () { return __importDefault(OSNotification_1).default; } }); | ||
Object.defineProperty(exports, "OSNotification", { enumerable: true, get: function () { return OSNotification_1.default; } }); |
@@ -1,2 +0,2 @@ | ||
import OSNotification from "../OSNotification"; | ||
import OSNotification from '../OSNotification'; | ||
export declare type OpenedEventActionType = 0 | 1; | ||
@@ -3,0 +3,0 @@ export interface OpenedEvent { |
{ | ||
"name": "react-native-onesignal", | ||
"version": "4.4.1", | ||
"version": "4.5.0", | ||
"description": "React Native OneSignal SDK", | ||
@@ -10,3 +10,3 @@ "main": "dist/index.js", | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"lint": "eslint src --ext .js,.jsx,.ts,.tsx; prettier --check src" | ||
}, | ||
@@ -16,2 +16,11 @@ "dependencies": { | ||
}, | ||
"devDependencies": { | ||
"@react-native-community/eslint-config": "^1.1.0", | ||
"@types/invariant": "^2.2.2", | ||
"@types/react-native": "^0.66.8", | ||
"eslint": "^6.5.1", | ||
"eslint-config-prettier": "^8.5.0", | ||
"prettier": "^2.7.1", | ||
"typescript": "^3.8.3" | ||
}, | ||
"keywords": [ | ||
@@ -37,7 +46,3 @@ "react-component", | ||
"author": "OneSignal <https://www.onesignal.com>, Geektime <http://www.geektime.co.il>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/invariant": "^2.2.2", | ||
"@types/react-native": "^0.66.8" | ||
} | ||
"license": "MIT" | ||
} |
@@ -1,16 +0,20 @@ | ||
import { EmitterSubscription, NativeEventEmitter, NativeModule } from 'react-native'; | ||
import { | ||
EmitterSubscription, | ||
NativeEventEmitter, | ||
NativeModule, | ||
} from 'react-native'; | ||
import NotificationReceivedEvent from './NotificationReceivedEvent'; | ||
import { isMultipleInstancesPossible } from '../helpers'; | ||
import { | ||
PERMISSION_CHANGED, | ||
SUBSCRIPTION_CHANGED, | ||
NOTIFICATION_WILL_SHOW, | ||
NOTIFICATION_OPENED, | ||
IN_APP_MESSAGE_CLICKED, | ||
EMAIL_SUBSCRIPTION_CHANGED, | ||
SMS_SUBSCRIPTION_CHANGED, | ||
IN_APP_MESSAGE_WILL_DISPLAY, | ||
IN_APP_MESSAGE_WILL_DISMISS, | ||
IN_APP_MESSAGE_DID_DISMISS, | ||
IN_APP_MESSAGE_DID_DISPLAY, | ||
PERMISSION_CHANGED, | ||
SUBSCRIPTION_CHANGED, | ||
NOTIFICATION_WILL_SHOW, | ||
NOTIFICATION_OPENED, | ||
IN_APP_MESSAGE_CLICKED, | ||
EMAIL_SUBSCRIPTION_CHANGED, | ||
SMS_SUBSCRIPTION_CHANGED, | ||
IN_APP_MESSAGE_WILL_DISPLAY, | ||
IN_APP_MESSAGE_WILL_DISMISS, | ||
IN_APP_MESSAGE_DID_DISMISS, | ||
IN_APP_MESSAGE_DID_DISPLAY, | ||
} from './events'; | ||
@@ -21,114 +25,120 @@ import { ChangeEvent } from '../models/Subscription'; | ||
const eventList = [ | ||
PERMISSION_CHANGED, | ||
SUBSCRIPTION_CHANGED, | ||
NOTIFICATION_WILL_SHOW, | ||
NOTIFICATION_OPENED, | ||
IN_APP_MESSAGE_CLICKED, | ||
EMAIL_SUBSCRIPTION_CHANGED, | ||
SMS_SUBSCRIPTION_CHANGED, | ||
IN_APP_MESSAGE_WILL_DISPLAY, | ||
IN_APP_MESSAGE_WILL_DISMISS, | ||
IN_APP_MESSAGE_DID_DISMISS, | ||
IN_APP_MESSAGE_DID_DISPLAY, | ||
] | ||
PERMISSION_CHANGED, | ||
SUBSCRIPTION_CHANGED, | ||
NOTIFICATION_WILL_SHOW, | ||
NOTIFICATION_OPENED, | ||
IN_APP_MESSAGE_CLICKED, | ||
EMAIL_SUBSCRIPTION_CHANGED, | ||
SMS_SUBSCRIPTION_CHANGED, | ||
IN_APP_MESSAGE_WILL_DISPLAY, | ||
IN_APP_MESSAGE_WILL_DISMISS, | ||
IN_APP_MESSAGE_DID_DISMISS, | ||
IN_APP_MESSAGE_DID_DISPLAY, | ||
]; | ||
export default class EventManager { | ||
private RNOneSignal: NativeModule; | ||
private oneSignalEventEmitter: NativeEventEmitter; | ||
private eventHandlerMap: Map<string, (event: any) => void>; | ||
private eventHandlerArrayMap: Map<string, Array<(event: any) => void>>; | ||
private listeners: { [key: string]: EmitterSubscription }; | ||
private RNOneSignal: NativeModule; | ||
private oneSignalEventEmitter: NativeEventEmitter; | ||
private eventHandlerMap: Map<string, (event: any) => void>; | ||
private eventHandlerArrayMap: Map<string, Array<(event: any) => void>>; | ||
private listeners: { [key: string]: EmitterSubscription }; | ||
constructor(RNOneSignal: NativeModule) { | ||
this.RNOneSignal = RNOneSignal; | ||
this.oneSignalEventEmitter = new NativeEventEmitter(RNOneSignal); | ||
this.eventHandlerMap = new Map(); // used for setters (single replacable callback) | ||
this.eventHandlerArrayMap = new Map(); // used for adders (multiple callbacks possible) | ||
this.listeners = {}; | ||
this.setupListeners(); | ||
constructor(RNOneSignal: NativeModule) { | ||
this.RNOneSignal = RNOneSignal; | ||
this.oneSignalEventEmitter = new NativeEventEmitter(RNOneSignal); | ||
this.eventHandlerMap = new Map(); // used for setters (single replacable callback) | ||
this.eventHandlerArrayMap = new Map(); // used for adders (multiple callbacks possible) | ||
this.listeners = {}; | ||
this.setupListeners(); | ||
} | ||
setupListeners(): void { | ||
// set up the event emitter and listeners | ||
if (this.RNOneSignal != null) { | ||
for (let i = 0; i < eventList.length; i++) { | ||
let eventName = eventList[i]; | ||
this.listeners[eventName] = this.generateEventListener(eventName); | ||
} | ||
} | ||
} | ||
setupListeners(): void { | ||
// set up the event emitter and listeners | ||
if (this.RNOneSignal != null) { | ||
// clear handlers | ||
clearHandlers(): void { | ||
this.eventHandlerMap = new Map(); | ||
this.eventHandlerArrayMap = new Map(); | ||
} | ||
for(let i = 0; i < eventList.length; i++) { | ||
let eventName = eventList[i]; | ||
this.listeners[eventName] = this.generateEventListener(eventName); | ||
} | ||
} | ||
} | ||
/** | ||
* Sets the event handler on the JS side of the bridge | ||
* Supports only one handler at a time | ||
* @param {string} eventName | ||
* @param {function} handler | ||
* @returns void | ||
*/ | ||
setEventHandler<T>(eventName: string, handler: (event: T) => void): void { | ||
this.eventHandlerMap.set(eventName, handler); | ||
} | ||
// clear handlers | ||
clearHandlers(): void { | ||
this.eventHandlerMap = new Map(); | ||
this.eventHandlerArrayMap = new Map(); | ||
} | ||
/** | ||
* Adds the event handler to the corresponding handler array on the JS side of the bridge | ||
* @param {string} eventName | ||
* @param {function} handler | ||
* @returns void | ||
*/ | ||
addEventHandler<T>( | ||
eventName: string, | ||
handler: (event: ChangeEvent<T>) => void, | ||
): void { | ||
let handlerArray = this.eventHandlerArrayMap.get(eventName); | ||
handlerArray && handlerArray.length > 0 | ||
? handlerArray.push(handler) | ||
: this.eventHandlerArrayMap.set(eventName, [handler]); | ||
} | ||
/** | ||
* Sets the event handler on the JS side of the bridge | ||
* Supports only one handler at a time | ||
* @param {string} eventName | ||
* @param {function} handler | ||
* @returns void | ||
*/ | ||
setEventHandler<T>(eventName: string, handler: (event: T) => void): void { | ||
this.eventHandlerMap.set(eventName, handler); | ||
} | ||
/** | ||
* clears the event handler(s) for the event name | ||
* @param {string} eventName | ||
* @returns void | ||
*/ | ||
clearEventHandler(eventName: string): void { | ||
this.eventHandlerArrayMap.delete(eventName); | ||
} | ||
/** | ||
* Adds the event handler to the corresponding handler array on the JS side of the bridge | ||
* @param {string} eventName | ||
* @param {function} handler | ||
* @returns void | ||
*/ | ||
addEventHandler<T>(eventName: string, handler: (event: ChangeEvent<T>) => void): void { | ||
// returns an event listener with the js to native mapping | ||
generateEventListener(eventName: string): EmitterSubscription { | ||
const addListenerCallback = (payload: Object) => { | ||
if (isMultipleInstancesPossible(eventName)) { | ||
// used for adders | ||
let handlerArray = this.eventHandlerArrayMap.get(eventName); | ||
handlerArray && handlerArray.length > 0 ? handlerArray.push(handler) : this.eventHandlerArrayMap.set(eventName, [handler]); | ||
} | ||
if (handlerArray) { | ||
handlerArray.forEach((handler) => { | ||
handler(payload); | ||
}); | ||
} | ||
} else { | ||
// used for setters | ||
let handler = this.eventHandlerMap.get(eventName); | ||
payload = this.getFinalPayload(eventName, payload); | ||
/** | ||
* clears the event handler(s) for the event name | ||
* @param {string} eventName | ||
* @returns void | ||
*/ | ||
clearEventHandler(eventName: string): void { | ||
this.eventHandlerArrayMap.delete(eventName); | ||
} | ||
// Check if we have added listener for this type yet | ||
if (handler) { | ||
handler(payload); | ||
} | ||
} | ||
}; | ||
// returns an event listener with the js to native mapping | ||
generateEventListener(eventName: string): EmitterSubscription { | ||
const addListenerCallback = (payload: Object) => { | ||
if (isMultipleInstancesPossible(eventName)) { | ||
// used for adders | ||
let handlerArray = this.eventHandlerArrayMap.get(eventName); | ||
if (handlerArray) { | ||
handlerArray.forEach(handler => { | ||
handler(payload); | ||
}); | ||
} | ||
} else { | ||
// used for setters | ||
let handler = this.eventHandlerMap.get(eventName); | ||
payload = this.getFinalPayload(eventName, payload); | ||
return this.oneSignalEventEmitter.addListener( | ||
eventName, | ||
addListenerCallback, | ||
); | ||
} | ||
// Check if we have added listener for this type yet | ||
if (handler) { | ||
handler(payload); | ||
} | ||
} | ||
}; | ||
return this.oneSignalEventEmitter.addListener(eventName, addListenerCallback); | ||
getFinalPayload(eventName: string, payload: Object): Object { | ||
switch (eventName) { | ||
case NOTIFICATION_WILL_SHOW: | ||
return new NotificationReceivedEvent(payload as OSNotification); | ||
default: | ||
return payload; | ||
} | ||
getFinalPayload(eventName: string, payload: Object): Object { | ||
switch(eventName) { | ||
case NOTIFICATION_WILL_SHOW: | ||
return new NotificationReceivedEvent(payload as OSNotification); | ||
default: | ||
return payload; | ||
} | ||
} | ||
} | ||
} | ||
// events | ||
export const NOTIFICATION_WILL_SHOW = 'OneSignal-notificationWillShowInForeground'; | ||
export const NOTIFICATION_OPENED = 'OneSignal-remoteNotificationOpened' | ||
export const NOTIFICATION_WILL_SHOW = | ||
'OneSignal-notificationWillShowInForeground'; | ||
export const NOTIFICATION_OPENED = 'OneSignal-remoteNotificationOpened'; | ||
export const IN_APP_MESSAGE_CLICKED = 'OneSignal-inAppMessageClicked'; | ||
@@ -15,2 +16,2 @@ | ||
export const EMAIL_SUBSCRIPTION_CHANGED = 'OneSignal-emailSubscriptionChanged'; | ||
export const SMS_SUBSCRIPTION_CHANGED = 'OneSignal-smsSubscriptionChanged'; | ||
export const SMS_SUBSCRIPTION_CHANGED = 'OneSignal-smsSubscriptionChanged'; |
@@ -6,25 +6,28 @@ import { NativeModules } from 'react-native'; | ||
export default class NotificationReceivedEvent { | ||
private notification: OSNotification; | ||
private notification: OSNotification; | ||
constructor(receivedEvent: OSNotification){ | ||
this.notification = new OSNotification(receivedEvent); | ||
constructor(receivedEvent: OSNotification) { | ||
this.notification = new OSNotification(receivedEvent); | ||
} | ||
complete(notification?: OSNotification): void { | ||
if (!notification) { | ||
// if the notificationReceivedEvent is null, we want to call the native-side | ||
// complete/completion with null to silence the notification | ||
RNOneSignal.completeNotificationEvent( | ||
this.notification.notificationId, | ||
false, | ||
); | ||
return; | ||
} | ||
complete(notification?: OSNotification): void { | ||
if (!notification) { | ||
// if the notificationReceivedEvent is null, we want to call the native-side | ||
// complete/completion with null to silence the notification | ||
RNOneSignal.completeNotificationEvent(this.notification.notificationId, false); | ||
return; | ||
} | ||
// if the notificationReceivedEvent is not null, we want to pass the specific event | ||
// future: Android side: make the notification modifiable | ||
// iOS & Android: the notification id is associated with the native-side complete handler / completion block | ||
RNOneSignal.completeNotificationEvent(notification.notificationId, true); | ||
} | ||
// if the notificationReceivedEvent is not null, we want to pass the specific event | ||
// future: Android side: make the notification modifiable | ||
// iOS & Android: the notification id is associated with the native-side complete handler / completion block | ||
RNOneSignal.completeNotificationEvent(notification.notificationId, true); | ||
} | ||
getNotification(): OSNotification { | ||
return this.notification; | ||
} | ||
getNotification(): OSNotification { | ||
return this.notification; | ||
} | ||
} |
import invariant from 'invariant'; | ||
import { NativeModule } from 'react-native'; | ||
import { | ||
PERMISSION_CHANGED, | ||
SUBSCRIPTION_CHANGED, | ||
EMAIL_SUBSCRIPTION_CHANGED, | ||
SMS_SUBSCRIPTION_CHANGED | ||
PERMISSION_CHANGED, | ||
SUBSCRIPTION_CHANGED, | ||
EMAIL_SUBSCRIPTION_CHANGED, | ||
SMS_SUBSCRIPTION_CHANGED, | ||
} from './events/events'; | ||
export function isValidCallback(handler: Function) { | ||
invariant( | ||
typeof handler === 'function', | ||
'Must provide a valid callback' | ||
); | ||
invariant(typeof handler === 'function', 'Must provide a valid callback'); | ||
} | ||
export function isNativeModuleLoaded(module: NativeModule): boolean { | ||
if (module == null) { | ||
console.error("Could not load RNOneSignal native module. Make sure native dependencies are properly linked."); | ||
return false; | ||
} | ||
return true; | ||
if (module == null) { | ||
console.error( | ||
'Could not load RNOneSignal native module. Make sure native dependencies are properly linked.', | ||
); | ||
return false; | ||
} | ||
return true; | ||
} | ||
@@ -30,11 +29,11 @@ | ||
export function isMultipleInstancesPossible(eventName: string) { | ||
switch(eventName){ | ||
case PERMISSION_CHANGED: | ||
case SUBSCRIPTION_CHANGED: | ||
case EMAIL_SUBSCRIPTION_CHANGED: | ||
case SMS_SUBSCRIPTION_CHANGED: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
switch (eventName) { | ||
case PERMISSION_CHANGED: | ||
case SUBSCRIPTION_CHANGED: | ||
case EMAIL_SUBSCRIPTION_CHANGED: | ||
case SMS_SUBSCRIPTION_CHANGED: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} |
1572
src/index.ts
@@ -6,21 +6,21 @@ 'use strict'; | ||
import { | ||
PERMISSION_CHANGED, | ||
SUBSCRIPTION_CHANGED, | ||
IN_APP_MESSAGE_CLICKED, | ||
NOTIFICATION_WILL_SHOW, | ||
NOTIFICATION_OPENED, | ||
EMAIL_SUBSCRIPTION_CHANGED, | ||
SMS_SUBSCRIPTION_CHANGED, | ||
IN_APP_MESSAGE_WILL_DISPLAY, | ||
IN_APP_MESSAGE_WILL_DISMISS, | ||
IN_APP_MESSAGE_DID_DISMISS, | ||
IN_APP_MESSAGE_DID_DISPLAY, | ||
PERMISSION_CHANGED, | ||
SUBSCRIPTION_CHANGED, | ||
IN_APP_MESSAGE_CLICKED, | ||
NOTIFICATION_WILL_SHOW, | ||
NOTIFICATION_OPENED, | ||
EMAIL_SUBSCRIPTION_CHANGED, | ||
SMS_SUBSCRIPTION_CHANGED, | ||
IN_APP_MESSAGE_WILL_DISPLAY, | ||
IN_APP_MESSAGE_WILL_DISMISS, | ||
IN_APP_MESSAGE_DID_DISMISS, | ||
IN_APP_MESSAGE_DID_DISPLAY, | ||
} from './events/events'; | ||
import { | ||
DeviceState, | ||
ChangeEvent, | ||
PermissionChange, | ||
SubscriptionChange, | ||
EmailSubscriptionChange, | ||
SMSSubscriptionChange, | ||
DeviceState, | ||
ChangeEvent, | ||
PermissionChange, | ||
SubscriptionChange, | ||
EmailSubscriptionChange, | ||
SMSSubscriptionChange, | ||
} from './models/Subscription'; | ||
@@ -30,3 +30,7 @@ import NotificationReceivedEvent from './events/NotificationReceivedEvent'; | ||
import { OutcomeEvent } from './models/Outcomes'; | ||
import { InAppMessage, InAppMessageAction, InAppMessageLifecycleHandlerObject } from './models/InAppMessage'; | ||
import { | ||
InAppMessage, | ||
InAppMessageAction, | ||
InAppMessageLifecycleHandlerObject, | ||
} from './models/InAppMessage'; | ||
import { isValidCallback, isNativeModuleLoaded } from './helpers'; | ||
@@ -41,793 +45,1065 @@ | ||
export default class OneSignal { | ||
/* I N I T I A L I Z A T I O N */ | ||
/* I N I T I A L I Z A T I O N */ | ||
/** | ||
* Completes OneSignal initialization by setting the OneSignal Application ID. | ||
* @param {string} appId | ||
* @returns void | ||
*/ | ||
static setAppId(appId: string): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.setAppId(appId); | ||
/** | ||
* Completes OneSignal initialization by setting the OneSignal Application ID. | ||
* @param {string} appId | ||
* @returns void | ||
*/ | ||
static setAppId(appId: string): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.setAppId(appId); | ||
} | ||
/* O B S E R V E R S */ | ||
/* O B S E R V E R S */ | ||
/** | ||
* Add a callback that fires when the native push permission changes. | ||
* @param {(event:ChangeEvent<PermissionChange>) => void} observer | ||
* @returns void | ||
*/ | ||
static addPermissionObserver(observer: (event: ChangeEvent<PermissionChange>) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
isValidCallback(observer); | ||
RNOneSignal.addPermissionObserver(); | ||
eventManager.addEventHandler<PermissionChange>(PERMISSION_CHANGED, observer); | ||
/** | ||
* Add a callback that fires when the native push permission changes. | ||
* @param {(event:ChangeEvent<PermissionChange>) => void} observer | ||
* @returns void | ||
*/ | ||
static addPermissionObserver( | ||
observer: (event: ChangeEvent<PermissionChange>) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
isValidCallback(observer); | ||
RNOneSignal.addPermissionObserver(); | ||
eventManager.addEventHandler<PermissionChange>( | ||
PERMISSION_CHANGED, | ||
observer, | ||
); | ||
} | ||
/** | ||
* Clears current permission observers. | ||
* @returns void | ||
*/ | ||
static clearPermissionObservers(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.removePermissionObserver(); | ||
eventManager.clearEventHandler(PERMISSION_CHANGED); | ||
/** | ||
* Clears current permission observers. | ||
* @returns void | ||
*/ | ||
static clearPermissionObservers(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.removePermissionObserver(); | ||
eventManager.clearEventHandler(PERMISSION_CHANGED); | ||
} | ||
/** | ||
* Add a callback that fires when the OneSignal subscription state changes. | ||
* @param {(event:ChangeEvent<SubscriptionChange>) => void} observer | ||
* @returns void | ||
*/ | ||
static addSubscriptionObserver(observer: (event: ChangeEvent<SubscriptionChange>) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
isValidCallback(observer); | ||
RNOneSignal.addSubscriptionObserver(); | ||
eventManager.addEventHandler<SubscriptionChange>(SUBSCRIPTION_CHANGED, observer); | ||
/** | ||
* Add a callback that fires when the OneSignal subscription state changes. | ||
* @param {(event:ChangeEvent<SubscriptionChange>) => void} observer | ||
* @returns void | ||
*/ | ||
static addSubscriptionObserver( | ||
observer: (event: ChangeEvent<SubscriptionChange>) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
isValidCallback(observer); | ||
RNOneSignal.addSubscriptionObserver(); | ||
eventManager.addEventHandler<SubscriptionChange>( | ||
SUBSCRIPTION_CHANGED, | ||
observer, | ||
); | ||
} | ||
/** | ||
* Clears current subscription observers. | ||
* @returns void | ||
*/ | ||
static clearSubscriptionObservers(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.removeSubscriptionObserver(); | ||
eventManager.clearEventHandler(SUBSCRIPTION_CHANGED); | ||
/** | ||
* Clears current subscription observers. | ||
* @returns void | ||
*/ | ||
static clearSubscriptionObservers(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.removeSubscriptionObserver(); | ||
eventManager.clearEventHandler(SUBSCRIPTION_CHANGED); | ||
} | ||
/** | ||
* Add a callback that fires when the OneSignal email subscription changes. | ||
* @param {(event:ChangeEvent<EmailSubscriptionChange>) => void} observer | ||
* @returns void | ||
*/ | ||
static addEmailSubscriptionObserver(observer: (event: ChangeEvent<EmailSubscriptionChange>) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
isValidCallback(observer); | ||
RNOneSignal.addEmailSubscriptionObserver(); | ||
eventManager.addEventHandler<EmailSubscriptionChange>(EMAIL_SUBSCRIPTION_CHANGED, observer); | ||
/** | ||
* Add a callback that fires when the OneSignal email subscription changes. | ||
* @param {(event:ChangeEvent<EmailSubscriptionChange>) => void} observer | ||
* @returns void | ||
*/ | ||
static addEmailSubscriptionObserver( | ||
observer: (event: ChangeEvent<EmailSubscriptionChange>) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
isValidCallback(observer); | ||
RNOneSignal.addEmailSubscriptionObserver(); | ||
eventManager.addEventHandler<EmailSubscriptionChange>( | ||
EMAIL_SUBSCRIPTION_CHANGED, | ||
observer, | ||
); | ||
} | ||
/** | ||
* Clears current email subscription observers. | ||
* @returns void | ||
*/ | ||
static clearEmailSubscriptionObservers(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.removeEmailSubscriptionObserver(); | ||
eventManager.clearEventHandler(EMAIL_SUBSCRIPTION_CHANGED); | ||
/** | ||
* Clears current email subscription observers. | ||
* @returns void | ||
*/ | ||
static clearEmailSubscriptionObservers(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.removeEmailSubscriptionObserver(); | ||
eventManager.clearEventHandler(EMAIL_SUBSCRIPTION_CHANGED); | ||
} | ||
/** | ||
* Add a callback that fires when the OneSignal sms subscription changes. | ||
* @param {(event:ChangeEvent<SMSSubscriptionChange>) => void} observer | ||
* @returns void | ||
*/ | ||
static addSMSSubscriptionObserver(observer: (event: ChangeEvent<SMSSubscriptionChange>) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
isValidCallback(observer); | ||
RNOneSignal.addSMSSubscriptionObserver(); | ||
eventManager.addEventHandler<SMSSubscriptionChange>(SMS_SUBSCRIPTION_CHANGED, observer); | ||
/** | ||
* Add a callback that fires when the OneSignal sms subscription changes. | ||
* @param {(event:ChangeEvent<SMSSubscriptionChange>) => void} observer | ||
* @returns void | ||
*/ | ||
static addSMSSubscriptionObserver( | ||
observer: (event: ChangeEvent<SMSSubscriptionChange>) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
isValidCallback(observer); | ||
RNOneSignal.addSMSSubscriptionObserver(); | ||
eventManager.addEventHandler<SMSSubscriptionChange>( | ||
SMS_SUBSCRIPTION_CHANGED, | ||
observer, | ||
); | ||
} | ||
/** | ||
* Clears current SMS subscription observers. | ||
* @returns void | ||
*/ | ||
static clearSMSSubscriptionObservers(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.removeSMSSubscriptionObserver(); | ||
eventManager.clearEventHandler(SMS_SUBSCRIPTION_CHANGED); | ||
/** | ||
* Clears current SMS subscription observers. | ||
* @returns void | ||
*/ | ||
static clearSMSSubscriptionObservers(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.removeSMSSubscriptionObserver(); | ||
eventManager.clearEventHandler(SMS_SUBSCRIPTION_CHANGED); | ||
} | ||
/* H A N D L E R S */ | ||
/* H A N D L E R S */ | ||
/** | ||
* Sets the handler that fires before the notification is displayed | ||
* Callback parameter is a `NotificationReceivedEvent` with: | ||
* - notification data | ||
* - `complete` function that accepts the `NotificationReceivedEvent` | ||
* @param {(event:NotificationReceivedEvent) => void} handler | ||
*/ | ||
static setNotificationWillShowInForegroundHandler(handler: (event: NotificationReceivedEvent) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
isValidCallback(handler); | ||
RNOneSignal.setNotificationWillShowInForegroundHandler(); | ||
eventManager.setEventHandler<NotificationReceivedEvent>(NOTIFICATION_WILL_SHOW, handler); | ||
/** | ||
* Sets the handler that fires before the notification is displayed | ||
* Callback parameter is a `NotificationReceivedEvent` with: | ||
* - notification data | ||
* - `complete` function that accepts the `NotificationReceivedEvent` | ||
* @param {(event:NotificationReceivedEvent) => void} handler | ||
*/ | ||
static setNotificationWillShowInForegroundHandler( | ||
handler: (event: NotificationReceivedEvent) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
isValidCallback(handler); | ||
RNOneSignal.setNotificationWillShowInForegroundHandler(); | ||
eventManager.setEventHandler<NotificationReceivedEvent>( | ||
NOTIFICATION_WILL_SHOW, | ||
handler, | ||
); | ||
} | ||
/** | ||
* Set the callback to run on notification open. | ||
* @param {(openedEvent:OpenedEvent) => void} handler | ||
* @returns void | ||
*/ | ||
static setNotificationOpenedHandler(handler: (openedEvent: OpenedEvent) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
isValidCallback(handler); | ||
RNOneSignal.setNotificationOpenedHandler(); | ||
eventManager.setEventHandler<OpenedEvent>(NOTIFICATION_OPENED, handler); | ||
/** | ||
* Set the callback to run on notification open. | ||
* @param {(openedEvent:OpenedEvent) => void} handler | ||
* @returns void | ||
*/ | ||
static setNotificationOpenedHandler( | ||
handler: (openedEvent: OpenedEvent) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
isValidCallback(handler); | ||
/* R E G I S T R A T I O N E T C */ | ||
RNOneSignal.setNotificationOpenedHandler(); | ||
eventManager.setEventHandler<OpenedEvent>(NOTIFICATION_OPENED, handler); | ||
} | ||
/** | ||
* Prompts the user for push notifications permission in iOS and Android 13+. | ||
* Use the fallbackToSettings parameter to prompt to open the settings app if a user has already declined push permissions. | ||
* | ||
* Call with promptForPushNotificationsWithUserResponse(fallbackToSettings?, handler?) | ||
* | ||
* Recommended: Do not use and instead follow: https://documentation.onesignal.com/docs/ios-push-opt-in-prompt. | ||
* @param {boolean} fallbackToSettings | ||
* @param {(response:boolean) => void} handler | ||
* @returns void | ||
*/ | ||
static promptForPushNotificationsWithUserResponse(fallbackToSettingsOrHandler?: boolean | ((response: boolean) => void), handler?: (response: boolean) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
/* R E G I S T R A T I O N E T C */ | ||
let fallbackToSettings = false; | ||
/** | ||
* Prompts the user for push notifications permission in iOS and Android 13+. | ||
* Use the fallbackToSettings parameter to prompt to open the settings app if a user has already declined push permissions. | ||
* | ||
* Call with promptForPushNotificationsWithUserResponse(fallbackToSettings?, handler?) | ||
* | ||
* Recommended: Do not use and instead follow: https://documentation.onesignal.com/docs/ios-push-opt-in-prompt. | ||
* @param {boolean} fallbackToSettings | ||
* @param {(response:boolean) => void} handler | ||
* @returns void | ||
*/ | ||
static promptForPushNotificationsWithUserResponse( | ||
fallbackToSettingsOrHandler?: boolean | ((response: boolean) => void), | ||
handler?: (response: boolean) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (typeof fallbackToSettingsOrHandler === "function") { | ||
// Method was called like promptForPushNotificationsWithUserResponse(handler: function) | ||
handler = fallbackToSettingsOrHandler; | ||
} | ||
else if (typeof fallbackToSettingsOrHandler === "boolean") { | ||
// Method was called like promptForPushNotificationsWithUserResponse(fallbackToSettings: boolean, handler?: function) | ||
fallbackToSettings = fallbackToSettingsOrHandler; | ||
} | ||
// Else method was called like promptForPushNotificationsWithUserResponse(), no need to modify | ||
let fallbackToSettings = false; | ||
if (!handler && Platform.OS === 'ios') { | ||
handler = function(){}; | ||
} | ||
if (typeof fallbackToSettingsOrHandler === 'function') { | ||
// Method was called like promptForPushNotificationsWithUserResponse(handler: function) | ||
handler = fallbackToSettingsOrHandler; | ||
} else if (typeof fallbackToSettingsOrHandler === 'boolean') { | ||
// Method was called like promptForPushNotificationsWithUserResponse(fallbackToSettings: boolean, handler?: function) | ||
fallbackToSettings = fallbackToSettingsOrHandler; | ||
} | ||
// Else method was called like promptForPushNotificationsWithUserResponse(), no need to modify | ||
RNOneSignal.promptForPushNotificationsWithUserResponse(fallbackToSettings, handler); | ||
if (!handler && Platform.OS === 'ios') { | ||
handler = function () {}; | ||
} | ||
/** | ||
* Only applies to iOS (does nothing on Android as it always silently registers) | ||
* Request for Direct-To-History push notification authorization | ||
* | ||
* For more information: https://documentation.onesignal.com/docs/ios-customizations#provisional-push-notifications | ||
* | ||
* @param {(response:boolean) => void} handler | ||
* @returns void | ||
*/ | ||
static registerForProvisionalAuthorization(handler: (response: boolean) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.promptForPushNotificationsWithUserResponse( | ||
fallbackToSettings, | ||
handler, | ||
); | ||
} | ||
if (Platform.OS === 'ios') { | ||
isValidCallback(handler); | ||
RNOneSignal.registerForProvisionalAuthorization(handler); | ||
} else { | ||
console.log("registerForProvisionalAuthorization: this function is not supported on Android"); | ||
} | ||
/** | ||
* Only applies to iOS (does nothing on Android as it always silently registers) | ||
* Request for Direct-To-History push notification authorization | ||
* | ||
* For more information: https://documentation.onesignal.com/docs/ios-customizations#provisional-push-notifications | ||
* | ||
* @param {(response:boolean) => void} handler | ||
* @returns void | ||
*/ | ||
static registerForProvisionalAuthorization( | ||
handler: (response: boolean) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Disable the push notification subscription to OneSignal. | ||
* @param {boolean} disable | ||
* @returns void | ||
*/ | ||
static disablePush(disable: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
if (Platform.OS === 'ios') { | ||
isValidCallback(handler); | ||
RNOneSignal.registerForProvisionalAuthorization(handler); | ||
} else { | ||
console.log( | ||
'registerForProvisionalAuthorization: this function is not supported on Android', | ||
); | ||
} | ||
} | ||
RNOneSignal.disablePush(disable); | ||
/** | ||
* Disable the push notification subscription to OneSignal. | ||
* @param {boolean} disable | ||
* @returns void | ||
*/ | ||
static disablePush(disable: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Android Only. If notifications are disabled for your application, unsubscribe the user from OneSignal. | ||
* @param {boolean} unsubscribe | ||
* @returns void | ||
*/ | ||
static unsubscribeWhenNotificationsAreDisabled(unsubscribe: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.disablePush(disable); | ||
} | ||
if (Platform.OS === 'android') { | ||
RNOneSignal.unsubscribeWhenNotificationsAreDisabled(unsubscribe); | ||
} else { | ||
console.log("unsubscribeWhenNotificationsAreDisabled: this function is not supported on iOS"); | ||
} | ||
/** | ||
* Android Only. If notifications are disabled for your application, unsubscribe the user from OneSignal. | ||
* @param {boolean} unsubscribe | ||
* @returns void | ||
*/ | ||
static unsubscribeWhenNotificationsAreDisabled(unsubscribe: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/* L O C A T I O N */ | ||
if (Platform.OS === 'android') { | ||
RNOneSignal.unsubscribeWhenNotificationsAreDisabled(unsubscribe); | ||
} else { | ||
console.log( | ||
'unsubscribeWhenNotificationsAreDisabled: this function is not supported on iOS', | ||
); | ||
} | ||
} | ||
/* L I V E A C T I V I T Y */ | ||
/** | ||
* True if the application has location share activated, false otherwise | ||
* @returns Promise<boolean> | ||
*/ | ||
static isLocationShared(): Promise<boolean> { | ||
// must return a promise | ||
if (!isNativeModuleLoaded(RNOneSignal)) return Promise.resolve(false); | ||
return RNOneSignal.isLocationShared(); | ||
/** | ||
* Associates a temporary push token with an Activity ID on the OneSignal server. | ||
* @param {string} activityId | ||
* @param {string} token | ||
* @param {Function} handler | ||
* @returns void | ||
*/ | ||
static enterLiveActivity( | ||
activityId: string, | ||
token: string, | ||
handler?: Function, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Disable or enable location collection (defaults to enabled if your app has location permission). | ||
* @param {boolean} shared | ||
* @returns void | ||
*/ | ||
static setLocationShared(shared: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
if (!handler) { | ||
handler = function () {}; | ||
} | ||
RNOneSignal.setLocationShared(shared); | ||
// Only Available on iOS | ||
if (Platform.OS === 'ios') { | ||
RNOneSignal.enterLiveActivity(activityId, token, handler); | ||
} | ||
} | ||
/** | ||
* Prompts the user for location permissions to allow geotagging from the OneSignal dashboard. | ||
* @returns void | ||
*/ | ||
static promptLocation(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
/** | ||
* Deletes activityId associated temporary push token on the OneSignal server. | ||
* @param {string} activityId | ||
* @param {Function} handler | ||
* @returns void | ||
*/ | ||
static exitLiveActivity(activityId: string, handler?: Function): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
//Supported in both iOS & Android | ||
RNOneSignal.promptLocation(); | ||
if (!handler) { | ||
handler = function () {}; | ||
} | ||
/* D E V I C E I N F O */ | ||
// Only Available on iOS | ||
if (Platform.OS === 'ios') { | ||
RNOneSignal.exitLiveActivity(activityId, handler); | ||
} | ||
} | ||
/** | ||
* Gets the device state. | ||
* This method returns a "snapshot" of the device state for when it was called. | ||
* @returns Promise<DeviceState | null> | ||
*/ | ||
static async getDeviceState(): Promise<DeviceState | null> { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return Promise.resolve(null); | ||
const deviceState = await RNOneSignal.getDeviceState(); | ||
/* L O C A T I O N */ | ||
if (Platform.OS === 'android') { | ||
deviceState['hasNotificationPermission'] = deviceState['areNotificationsEnabled']; | ||
delete deviceState['areNotificationsEnabled']; | ||
} | ||
/** | ||
* True if the application has location share activated, false otherwise | ||
* @returns Promise<boolean> | ||
*/ | ||
static isLocationShared(): Promise<boolean> { | ||
// must return a promise | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return Promise.resolve(false); | ||
} | ||
return RNOneSignal.isLocationShared(); | ||
} | ||
return deviceState; | ||
/** | ||
* Disable or enable location collection (defaults to enabled if your app has location permission). | ||
* @param {boolean} shared | ||
* @returns void | ||
*/ | ||
static setLocationShared(shared: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Allows you to set the app defined language with the OneSignal SDK. | ||
* @param {string} language | ||
* @param {(success:object) => void} onSuccess | ||
* @param {(failure:object) => void} onFailure | ||
* @returns void | ||
*/ | ||
static setLanguage(language: string, onSuccess?: (success: object) => void, onFailure?: (failure: object) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.setLocationShared(shared); | ||
} | ||
if (!onSuccess) { | ||
onSuccess = function(){}; | ||
} | ||
if (!onFailure) { | ||
onFailure = function(){}; | ||
} | ||
RNOneSignal.setLanguage(language, onSuccess, onFailure); | ||
/** | ||
* Prompts the user for location permissions to allow geotagging from the OneSignal dashboard. | ||
* @returns void | ||
*/ | ||
static promptLocation(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/* T A G S */ | ||
//Supported in both iOS & Android | ||
RNOneSignal.promptLocation(); | ||
} | ||
/** | ||
* Tag a user based on an app event of your choosing so they can be targeted later via segments. | ||
* @param {string} key | ||
* @param {string} value | ||
* @returns void | ||
*/ | ||
static sendTag(key: string, value: string): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
/* D E V I C E I N F O */ | ||
if (!key || (!value && value !== "")) { | ||
console.error("OneSignal: sendTag: must include a key and a value"); | ||
} | ||
/** | ||
* Gets the device state. | ||
* This method returns a "snapshot" of the device state for when it was called. | ||
* @returns Promise<DeviceState | null> | ||
*/ | ||
static async getDeviceState(): Promise<DeviceState | null> { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return Promise.resolve(null); | ||
} | ||
const deviceState = await RNOneSignal.getDeviceState(); | ||
RNOneSignal.sendTag(key, value); | ||
if (Platform.OS === 'android') { | ||
deviceState.hasNotificationPermission = | ||
deviceState.areNotificationsEnabled; | ||
delete deviceState.areNotificationsEnabled; | ||
} | ||
/** | ||
* Tag a user with multiple tags based on an app event of your choosing so they can be targeted later via segments. | ||
* @param {[key: string]: string} tags | ||
* @returns void | ||
*/ | ||
static sendTags(tags: { [key: string]: string }): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
let keys = Object.keys(tags); | ||
return deviceState; | ||
} | ||
if (keys.length === 0) { | ||
console.error(`OneSignal: sendTags: argument must be of type object of the form { key : 'value' }`); | ||
} | ||
RNOneSignal.sendTags(tags || {}); | ||
/** | ||
* Allows you to set the app defined language with the OneSignal SDK. | ||
* @param {string} language | ||
* @param {(success:object) => void} onSuccess | ||
* @param {(failure:object) => void} onFailure | ||
* @returns void | ||
*/ | ||
static setLanguage( | ||
language: string, | ||
onSuccess?: (success: object) => void, | ||
onFailure?: (failure: object) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Retrieve a list of tags that have been set on the user from the OneSignal server. | ||
* @param {(tags: {[key: string]: string} | null) => void} handler | ||
* @returns void | ||
*/ | ||
static getTags(handler: (tags: { [key: string]: string } | null) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.getTags(handler); | ||
if (!onSuccess) { | ||
onSuccess = function () {}; | ||
} | ||
/** | ||
* Deletes a single tag that was previously set on a user. | ||
* @param {string} key | ||
* @returns void | ||
*/ | ||
static deleteTag(key: string): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
if (typeof key !== "string") { | ||
console.error("OneSignal: deleteTag: key argument must be of type string"); | ||
} | ||
RNOneSignal.deleteTags([key]); | ||
if (!onFailure) { | ||
onFailure = function () {}; | ||
} | ||
RNOneSignal.setLanguage(language, onSuccess, onFailure); | ||
} | ||
/** | ||
* Deletes multiple tags that were previously set on a user. | ||
* @param {string[]} keys | ||
*/ | ||
static deleteTags(keys: string[]): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
/* T A G S */ | ||
if (!Array.isArray(keys)) { | ||
console.error("OneSignal: deleteTags: argument must be of array type"); | ||
} | ||
/** | ||
* Tag a user based on an app event of your choosing so they can be targeted later via segments. | ||
* @param {string} key | ||
* @param {string} value | ||
* @returns void | ||
*/ | ||
static sendTag(key: string, value: string): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.deleteTags(keys) | ||
if (!key || (!value && value !== '')) { | ||
console.error('OneSignal: sendTag: must include a key and a value'); | ||
} | ||
/* E M A I L */ | ||
RNOneSignal.sendTag(key, value); | ||
} | ||
/** | ||
* Allows you to set the user's email address with the OneSignal SDK. | ||
* @param {string} email | ||
* @param {string} emailAuthCode | ||
* @param {Function} handler | ||
* @returns void | ||
*/ | ||
static setEmail(email: string, emailAuthCode?: string | null, handler?: Function): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
/** | ||
* Tag a user with multiple tags based on an app event of your choosing so they can be targeted later via segments. | ||
* @param {[key: string]: string} tags | ||
* @returns void | ||
*/ | ||
static sendTags(tags: { [key: string]: string }): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
let keys = Object.keys(tags); | ||
if (emailAuthCode === undefined) | ||
emailAuthCode = null; | ||
if (keys.length === 0) { | ||
console.error( | ||
"OneSignal: sendTags: argument must be of type object of the form { key : 'value' }", | ||
); | ||
} | ||
// Android workaround for the current issue of callback fired more than once | ||
if (!handler && Platform.OS === 'ios') | ||
handler = function(){}; | ||
RNOneSignal.sendTags(tags || {}); | ||
} | ||
RNOneSignal.setEmail(email, emailAuthCode, handler); | ||
/** | ||
* Retrieve a list of tags that have been set on the user from the OneSignal server. | ||
* @param {(tags: {[key: string]: string} | null) => void} handler | ||
* @returns void | ||
*/ | ||
static getTags( | ||
handler: (tags: { [key: string]: string } | null) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.getTags(handler); | ||
} | ||
/** | ||
* If your app implements logout functionality, you can call logoutEmail to dissociate the email from the device. | ||
* @param {Function} handler | ||
*/ | ||
static logoutEmail(handler?: Function): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
/** | ||
* Deletes a single tag that was previously set on a user. | ||
* @param {string} key | ||
* @returns void | ||
*/ | ||
static deleteTag(key: string): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (typeof key !== 'string') { | ||
console.error( | ||
'OneSignal: deleteTag: key argument must be of type string', | ||
); | ||
} | ||
RNOneSignal.deleteTags([key]); | ||
} | ||
// Android workaround for the current issue of callback fired more than once | ||
if (!handler && Platform.OS === 'ios') | ||
handler = function(){}; | ||
/** | ||
* Deletes multiple tags that were previously set on a user. | ||
* @param {string[]} keys | ||
*/ | ||
static deleteTags(keys: string[]): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.logoutEmail(handler); | ||
if (!Array.isArray(keys)) { | ||
console.error('OneSignal: deleteTags: argument must be of array type'); | ||
} | ||
/* S M S */ | ||
RNOneSignal.deleteTags(keys); | ||
} | ||
/** | ||
* Allows you to set the user's SMS number with the OneSignal SDK. | ||
* @param {string} smsNumber | ||
* @param {string} smsAuthCode | ||
* @param {Function} handler | ||
* @returns void | ||
*/ | ||
static setSMSNumber(smsNumber: string, smsAuthCode?: string | null, handler?: Function): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
/* E M A I L */ | ||
if (smsAuthCode === undefined) | ||
smsAuthCode = null; | ||
/** | ||
* Allows you to set the user's email address with the OneSignal SDK. | ||
* @param {string} email | ||
* @param {string} emailAuthCode | ||
* @param {Function} handler | ||
* @returns void | ||
*/ | ||
static setEmail( | ||
email: string, | ||
emailAuthCode?: string | null, | ||
handler?: Function, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
// Android workaround for the current issue of callback fired more than once | ||
if (!handler && Platform.OS === 'ios') | ||
handler = function(){}; | ||
if (emailAuthCode === undefined) { | ||
emailAuthCode = null; | ||
} | ||
RNOneSignal.setSMSNumber(smsNumber, smsAuthCode, handler); | ||
// Android workaround for the current issue of callback fired more than once | ||
if (!handler && Platform.OS === 'ios') { | ||
handler = function () {}; | ||
} | ||
/** | ||
* If your app implements logout functionality, you can call logoutSMSNumber to dissociate the SMS number from the device. | ||
* @param {Function} handler | ||
*/ | ||
static logoutSMSNumber(handler?: Function): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.setEmail(email, emailAuthCode, handler); | ||
} | ||
// Android workaround for the current issue of callback fired more than once | ||
if (!handler && Platform.OS === 'ios') | ||
handler = function(){}; | ||
/** | ||
* If your app implements logout functionality, you can call logoutEmail to dissociate the email from the device. | ||
* @param {Function} handler | ||
*/ | ||
static logoutEmail(handler?: Function): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.logoutSMSNumber(handler); | ||
// Android workaround for the current issue of callback fired more than once | ||
if (!handler && Platform.OS === 'ios') { | ||
handler = function () {}; | ||
} | ||
/* N O T I F I C A T I O N S */ | ||
RNOneSignal.logoutEmail(handler); | ||
} | ||
/** | ||
* Send a notification | ||
* @param {string} notificationObjectString - JSON string payload (see REST API reference) | ||
* @param {(success:object) => void} onSuccess | ||
* @param {(failure:object) => void} onFailure | ||
* @returns void | ||
*/ | ||
static postNotification(notificationObjectString: string, onSuccess?: (success: object) => void, onFailure?: (failure: object) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
/* S M S */ | ||
if (!onSuccess) | ||
onSuccess = function(){}; | ||
/** | ||
* Allows you to set the user's SMS number with the OneSignal SDK. | ||
* @param {string} smsNumber | ||
* @param {string} smsAuthCode | ||
* @param {Function} handler | ||
* @returns void | ||
*/ | ||
static setSMSNumber( | ||
smsNumber: string, | ||
smsAuthCode?: string | null, | ||
handler?: Function, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (!onFailure) | ||
onFailure = function(){}; | ||
if (smsAuthCode === undefined) { | ||
smsAuthCode = null; | ||
} | ||
RNOneSignal.postNotification(notificationObjectString, onSuccess, onFailure); | ||
// Android workaround for the current issue of callback fired more than once | ||
if (!handler && Platform.OS === 'ios') { | ||
handler = function () {}; | ||
} | ||
/** | ||
* Android Only. iOS provides a standard way to clear notifications by clearing badge count. | ||
* @returns void | ||
*/ | ||
static clearOneSignalNotifications(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.setSMSNumber(smsNumber, smsAuthCode, handler); | ||
} | ||
if (Platform.OS === 'android') { | ||
RNOneSignal.clearOneSignalNotifications(); | ||
} else { | ||
console.log("clearOneSignalNotifications: this function is not supported on iOS"); | ||
} | ||
/** | ||
* If your app implements logout functionality, you can call logoutSMSNumber to dissociate the SMS number from the device. | ||
* @param {Function} handler | ||
*/ | ||
static logoutSMSNumber(handler?: Function): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Android Only. | ||
* Removes a single OneSignal notification based on its Android notification integer id. | ||
* @param {number} id - notification id to cancel | ||
* @returns void | ||
*/ | ||
static removeNotification(id: number): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
// Android workaround for the current issue of callback fired more than once | ||
if (!handler && Platform.OS === 'ios') { | ||
handler = function () {}; | ||
} | ||
if (Platform.OS === 'android') { | ||
RNOneSignal.removeNotification(id); | ||
} else { | ||
console.log("removeNotification: this function is not supported on iOS"); | ||
} | ||
RNOneSignal.logoutSMSNumber(handler); | ||
} | ||
/* N O T I F I C A T I O N S */ | ||
/** | ||
* Send a notification | ||
* @param {string} notificationObjectString - JSON string payload (see REST API reference) | ||
* @param {(success:object) => void} onSuccess | ||
* @param {(failure:object) => void} onFailure | ||
* @returns void | ||
*/ | ||
static postNotification( | ||
notificationObjectString: string, | ||
onSuccess?: (success: object) => void, | ||
onFailure?: (failure: object) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Android Only. | ||
* Removes all OneSignal notifications based on its Android notification group Id. | ||
* @param {string} id - notification group id to cancel | ||
* @returns void | ||
*/ | ||
static removeGroupedNotifications(id: string): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
if (!onSuccess) { | ||
onSuccess = function () {}; | ||
} | ||
if (Platform.OS === 'android') { | ||
RNOneSignal.removeGroupedNotifications(id); | ||
} else { | ||
console.log("removeGroupedNotifications: this function is not supported on iOS"); | ||
} | ||
if (!onFailure) { | ||
onFailure = function () {}; | ||
} | ||
/** | ||
* This method can be used to set if launch URLs should be opened in safari or within the application. | ||
* @param {boolean} isEnabled | ||
* @returns | ||
*/ | ||
static setLaunchURLsInApp(isEnabled: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.postNotification( | ||
notificationObjectString, | ||
onSuccess, | ||
onFailure, | ||
); | ||
} | ||
if (Platform.OS === 'ios') { | ||
RNOneSignal.setLaunchURLsInApp(isEnabled); | ||
} else { | ||
console.log("setLaunchURLsInApp: this function is not supported on Android"); | ||
} | ||
/** | ||
* Android Only. iOS provides a standard way to clear notifications by clearing badge count. | ||
* @returns void | ||
*/ | ||
static clearOneSignalNotifications(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/* E X T E R N A L U S E R I D */ | ||
if (Platform.OS === 'android') { | ||
RNOneSignal.clearOneSignalNotifications(); | ||
} else { | ||
console.log( | ||
'clearOneSignalNotifications: this function is not supported on iOS', | ||
); | ||
} | ||
} | ||
/** | ||
* Allows you to use your own system's user ID's to send push notifications to your users. | ||
* @param {string} externalId | ||
* @param {string} externalIdAuthCode? | ||
* @param {(results:object) => void} handler? | ||
* @returns void | ||
*/ | ||
static setExternalUserId(externalId: string, handlerOrAuth?: ((results: object) => void) | string, handler?: (results: object) => void): void { | ||
/** | ||
* Android Only. | ||
* Removes a single OneSignal notification based on its Android notification integer id. | ||
* @param {number} id - notification id to cancel | ||
* @returns void | ||
*/ | ||
static removeNotification(id: number): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
if (Platform.OS === 'android') { | ||
RNOneSignal.removeNotification(id); | ||
} else { | ||
console.log('removeNotification: this function is not supported on iOS'); | ||
} | ||
} | ||
if (typeof handlerOrAuth === "function") { | ||
RNOneSignal.setExternalUserId(externalId, null, handlerOrAuth); | ||
return; | ||
} | ||
/** | ||
* Android Only. | ||
* Removes all OneSignal notifications based on its Android notification group Id. | ||
* @param {string} id - notification group id to cancel | ||
* @returns void | ||
*/ | ||
static removeGroupedNotifications(id: string): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
if (!handler && Platform.OS === 'ios') { | ||
handler = function(){}; | ||
} | ||
if (Platform.OS === 'android') { | ||
RNOneSignal.removeGroupedNotifications(id); | ||
} else { | ||
console.log( | ||
'removeGroupedNotifications: this function is not supported on iOS', | ||
); | ||
} | ||
} | ||
RNOneSignal.setExternalUserId(externalId, handlerOrAuth, handler); | ||
/** | ||
* This method can be used to set if launch URLs should be opened in safari or within the application. | ||
* @param {boolean} isEnabled | ||
* @returns | ||
*/ | ||
static setLaunchURLsInApp(isEnabled: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Removes whatever was set as the current user's external user ID. | ||
* @param {(results:object) => void} handler | ||
* @returns void | ||
*/ | ||
static removeExternalUserId(handler?: (results: object) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
if (Platform.OS === 'ios') { | ||
RNOneSignal.setLaunchURLsInApp(isEnabled); | ||
} else { | ||
console.log( | ||
'setLaunchURLsInApp: this function is not supported on Android', | ||
); | ||
} | ||
} | ||
// Android workaround for the current issue of callback fired more than once | ||
if (handler === undefined && Platform.OS === 'ios') | ||
handler = function(){}; | ||
/* E X T E R N A L U S E R I D */ | ||
RNOneSignal.removeExternalUserId(handler); | ||
/** | ||
* Allows you to use your own system's user ID's to send push notifications to your users. | ||
* @param {string} externalId | ||
* @param {string} externalIdAuthCode? | ||
* @param {(results:object) => void} handler? | ||
* @returns void | ||
*/ | ||
static setExternalUserId( | ||
externalId: string, | ||
handlerOrAuth?: ((results: object) => void) | string, | ||
handler?: (results: object) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/* I N A P P M E S S A G I N G */ | ||
if (typeof handlerOrAuth === 'function') { | ||
RNOneSignal.setExternalUserId(externalId, null, handlerOrAuth); | ||
return; | ||
} | ||
/** | ||
* Sets an In-App Message click event handler. | ||
* @param {(action:InAppMessageAction) => void} handler | ||
* @returns void | ||
*/ | ||
static setInAppMessageClickHandler(handler: (action: InAppMessageAction) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
isValidCallback(handler); | ||
RNOneSignal.initInAppMessageClickHandlerParams(); | ||
RNOneSignal.setInAppMessageClickHandler(); | ||
eventManager.setEventHandler<InAppMessageAction>(IN_APP_MESSAGE_CLICKED, handler); | ||
if (!handler && Platform.OS === 'ios') { | ||
handler = function () {}; | ||
} | ||
/** | ||
* Sets the In-App Message lifecycle handler object to run on displaying and/or dismissing an In-App Message. | ||
* @param {InAppMessageLifecycleHandlerObject} handlerObject | ||
* @returns void | ||
*/ | ||
static setInAppMessageLifecycleHandler(handlerObject: InAppMessageLifecycleHandlerObject): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.setExternalUserId(externalId, handlerOrAuth, handler); | ||
} | ||
if (handlerObject.onWillDisplayInAppMessage) { | ||
isValidCallback(handlerObject.onWillDisplayInAppMessage); | ||
eventManager.setEventHandler<InAppMessage>(IN_APP_MESSAGE_WILL_DISPLAY, handlerObject.onWillDisplayInAppMessage); | ||
} | ||
if (handlerObject.onDidDisplayInAppMessage) { | ||
isValidCallback(handlerObject.onDidDisplayInAppMessage); | ||
eventManager.setEventHandler<InAppMessage>(IN_APP_MESSAGE_DID_DISPLAY, handlerObject.onDidDisplayInAppMessage); | ||
} | ||
if (handlerObject.onWillDismissInAppMessage) { | ||
isValidCallback(handlerObject.onWillDismissInAppMessage); | ||
eventManager.setEventHandler<InAppMessage>(IN_APP_MESSAGE_WILL_DISMISS, handlerObject.onWillDismissInAppMessage); | ||
} | ||
if (handlerObject.onDidDismissInAppMessage) { | ||
isValidCallback(handlerObject.onDidDismissInAppMessage); | ||
eventManager.setEventHandler<InAppMessage>(IN_APP_MESSAGE_DID_DISMISS, handlerObject.onDidDismissInAppMessage); | ||
} | ||
/** | ||
* Removes whatever was set as the current user's external user ID. | ||
* @param {(results:object) => void} handler | ||
* @returns void | ||
*/ | ||
static removeExternalUserId(handler?: (results: object) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.setInAppMessageLifecycleHandler(); | ||
// Android workaround for the current issue of callback fired more than once | ||
if (handler === undefined && Platform.OS === 'ios') { | ||
handler = function () {}; | ||
} | ||
/** | ||
* Add an In-App Message Trigger. | ||
* @param {string} key | ||
* @param {string | number | boolean} value | ||
* @returns void | ||
*/ | ||
static addTrigger(key: string, value: string | number | boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.removeExternalUserId(handler); | ||
} | ||
// value can be assigned to `false` so we cannot just check `!value` | ||
if (!key || value == null) { | ||
console.error("OneSignal: addTrigger: must include a key and a value"); | ||
} | ||
/* I N A P P M E S S A G I N G */ | ||
let trigger: { [key: string]: string | number | boolean } = {}; | ||
trigger[key] = value; | ||
RNOneSignal.addTriggers(trigger); | ||
/** | ||
* Sets an In-App Message click event handler. | ||
* @param {(action:InAppMessageAction) => void} handler | ||
* @returns void | ||
*/ | ||
static setInAppMessageClickHandler( | ||
handler: (action: InAppMessageAction) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
isValidCallback(handler); | ||
RNOneSignal.initInAppMessageClickHandlerParams(); | ||
RNOneSignal.setInAppMessageClickHandler(); | ||
eventManager.setEventHandler<InAppMessageAction>( | ||
IN_APP_MESSAGE_CLICKED, | ||
handler, | ||
); | ||
} | ||
/** | ||
* Adds Multiple In-App Message Triggers. | ||
* @param {[key: string]: string | number | boolean} triggers | ||
* @returns void | ||
*/ | ||
static addTriggers(triggers: { [key: string]: string | number | boolean }): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
/** | ||
* Sets the In-App Message lifecycle handler object to run on displaying and/or dismissing an In-App Message. | ||
* @param {InAppMessageLifecycleHandlerObject} handlerObject | ||
* @returns void | ||
*/ | ||
static setInAppMessageLifecycleHandler( | ||
handlerObject: InAppMessageLifecycleHandlerObject, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
let keys = Object.keys(triggers); | ||
if (handlerObject.onWillDisplayInAppMessage) { | ||
isValidCallback(handlerObject.onWillDisplayInAppMessage); | ||
eventManager.setEventHandler<InAppMessage>( | ||
IN_APP_MESSAGE_WILL_DISPLAY, | ||
handlerObject.onWillDisplayInAppMessage, | ||
); | ||
} | ||
if (handlerObject.onDidDisplayInAppMessage) { | ||
isValidCallback(handlerObject.onDidDisplayInAppMessage); | ||
eventManager.setEventHandler<InAppMessage>( | ||
IN_APP_MESSAGE_DID_DISPLAY, | ||
handlerObject.onDidDisplayInAppMessage, | ||
); | ||
} | ||
if (handlerObject.onWillDismissInAppMessage) { | ||
isValidCallback(handlerObject.onWillDismissInAppMessage); | ||
eventManager.setEventHandler<InAppMessage>( | ||
IN_APP_MESSAGE_WILL_DISMISS, | ||
handlerObject.onWillDismissInAppMessage, | ||
); | ||
} | ||
if (handlerObject.onDidDismissInAppMessage) { | ||
isValidCallback(handlerObject.onDidDismissInAppMessage); | ||
eventManager.setEventHandler<InAppMessage>( | ||
IN_APP_MESSAGE_DID_DISMISS, | ||
handlerObject.onDidDismissInAppMessage, | ||
); | ||
} | ||
if (keys.length === 0) { | ||
console.error(`OneSignal: addTriggers: argument must be an object of the form { key : 'value' }`); | ||
} | ||
RNOneSignal.setInAppMessageLifecycleHandler(); | ||
} | ||
RNOneSignal.addTriggers(triggers); | ||
/** | ||
* Add an In-App Message Trigger. | ||
* @param {string} key | ||
* @param {string | number | boolean} value | ||
* @returns void | ||
*/ | ||
static addTrigger(key: string, value: string | number | boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Removes a list of triggers based on a collection of keys. | ||
* @param {string[]} keys | ||
* @returns void | ||
*/ | ||
static removeTriggersForKeys(keys: string[]): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
// value can be assigned to `false` so we cannot just check `!value` | ||
if (!key || value == null) { | ||
console.error('OneSignal: addTrigger: must include a key and a value'); | ||
} | ||
RNOneSignal.removeTriggersForKeys(keys); | ||
let trigger: { [key: string]: string | number | boolean } = {}; | ||
trigger[key] = value; | ||
RNOneSignal.addTriggers(trigger); | ||
} | ||
/** | ||
* Adds Multiple In-App Message Triggers. | ||
* @param {[key: string]: string | number | boolean} triggers | ||
* @returns void | ||
*/ | ||
static addTriggers(triggers: { | ||
[key: string]: string | number | boolean; | ||
}): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Removes a list of triggers based on a key. | ||
* @param {string} key | ||
* @returns void | ||
*/ | ||
static removeTriggerForKey(key: string): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.removeTriggerForKey(key); | ||
let keys = Object.keys(triggers); | ||
if (keys.length === 0) { | ||
console.error( | ||
"OneSignal: addTriggers: argument must be an object of the form { key : 'value' }", | ||
); | ||
} | ||
/** | ||
* Gets a trigger value for a provided trigger key. | ||
* @param {string} key | ||
* @returns Promise<string | number | boolean | null> | ||
*/ | ||
static getTriggerValueForKey(key: string): Promise<string | number | boolean | null> { | ||
// must return a promise | ||
if (!isNativeModuleLoaded(RNOneSignal)) return Promise.resolve(null); | ||
return RNOneSignal.getTriggerValueForKey(key); | ||
RNOneSignal.addTriggers(triggers); | ||
} | ||
/** | ||
* Removes a list of triggers based on a collection of keys. | ||
* @param {string[]} keys | ||
* @returns void | ||
*/ | ||
static removeTriggersForKeys(keys: string[]): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Pause & unpause In-App Messages | ||
* @param {boolean} pause | ||
* @returns void | ||
*/ | ||
static pauseInAppMessages(pause: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.pauseInAppMessages(pause); | ||
RNOneSignal.removeTriggersForKeys(keys); | ||
} | ||
/** | ||
* Removes a list of triggers based on a key. | ||
* @param {string} key | ||
* @returns void | ||
*/ | ||
static removeTriggerForKey(key: string): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.removeTriggerForKey(key); | ||
} | ||
/* O U T C O M E S */ | ||
/** | ||
* Gets a trigger value for a provided trigger key. | ||
* @param {string} key | ||
* @returns Promise<string | number | boolean | null> | ||
*/ | ||
static getTriggerValueForKey( | ||
key: string, | ||
): Promise<string | number | boolean | null> { | ||
// must return a promise | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return Promise.resolve(null); | ||
} | ||
return RNOneSignal.getTriggerValueForKey(key); | ||
} | ||
/** | ||
* Increases the "Count" of this Outcome by 1 and will be counted each time sent. | ||
* @param {string} name | ||
* @param {(event:OutcomeEvent) => void} handler | ||
* @returns void | ||
*/ | ||
static sendOutcome(name: string, handler?: (event: OutcomeEvent) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
/** | ||
* Pause & unpause In-App Messages | ||
* @param {boolean} pause | ||
* @returns void | ||
*/ | ||
static pauseInAppMessages(pause: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
RNOneSignal.pauseInAppMessages(pause); | ||
} | ||
if (!handler) { | ||
handler = function(){}; | ||
} | ||
/* O U T C O M E S */ | ||
RNOneSignal.sendOutcome(name, handler); | ||
/** | ||
* Increases the "Count" of this Outcome by 1 and will be counted each time sent. | ||
* @param {string} name | ||
* @param {(event:OutcomeEvent) => void} handler | ||
* @returns void | ||
*/ | ||
static sendOutcome( | ||
name: string, | ||
handler?: (event: OutcomeEvent) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Increases "Count" by 1 only once. This can only be attributed to a single notification. | ||
* @param {string} name | ||
* @param {(event:OutcomeEvent) => void} handler | ||
* @returns void | ||
*/ | ||
static sendUniqueOutcome(name: string, handler?: (event: OutcomeEvent) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
if (!handler) { | ||
handler = function () {}; | ||
} | ||
if (!handler) { | ||
handler = function(){}; | ||
} | ||
RNOneSignal.sendOutcome(name, handler); | ||
} | ||
RNOneSignal.sendUniqueOutcome(name, handler); | ||
/** | ||
* Increases "Count" by 1 only once. This can only be attributed to a single notification. | ||
* @param {string} name | ||
* @param {(event:OutcomeEvent) => void} handler | ||
* @returns void | ||
*/ | ||
static sendUniqueOutcome( | ||
name: string, | ||
handler?: (event: OutcomeEvent) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Increases the "Count" of this Outcome by 1 and the "Sum" by the value. Will be counted each time sent. | ||
* If the method is called outside of an attribution window, it will be unattributed until a new session occurs. | ||
* @param {string} name | ||
* @param {string|number} value | ||
* @param {(event:OutcomeEvent) => void} handler | ||
* @returns void | ||
*/ | ||
static sendOutcomeWithValue(name: string, value: string | number, handler?: (event: OutcomeEvent) => void): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
if (!handler) { | ||
handler = function () {}; | ||
} | ||
if (!handler) { | ||
handler = function(){}; | ||
} | ||
RNOneSignal.sendUniqueOutcome(name, handler); | ||
} | ||
RNOneSignal.sendOutcomeWithValue(name, Number(value), handler); | ||
/** | ||
* Increases the "Count" of this Outcome by 1 and the "Sum" by the value. Will be counted each time sent. | ||
* If the method is called outside of an attribution window, it will be unattributed until a new session occurs. | ||
* @param {string} name | ||
* @param {string|number} value | ||
* @param {(event:OutcomeEvent) => void} handler | ||
* @returns void | ||
*/ | ||
static sendOutcomeWithValue( | ||
name: string, | ||
value: string | number, | ||
handler?: (event: OutcomeEvent) => void, | ||
): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/* P R I V A C Y C O N S E N T */ | ||
if (!handler) { | ||
handler = function () {}; | ||
} | ||
/** | ||
* Did the user provide privacy consent for GDPR purposes. | ||
* @returns Promise<boolean> | ||
*/ | ||
static userProvidedPrivacyConsent(): Promise<boolean> { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return Promise.resolve(false); | ||
RNOneSignal.sendOutcomeWithValue(name, Number(value), handler); | ||
} | ||
//returns a promise | ||
return RNOneSignal.userProvidedPrivacyConsent(); | ||
/* P R I V A C Y C O N S E N T */ | ||
/** | ||
* Did the user provide privacy consent for GDPR purposes. | ||
* @returns Promise<boolean> | ||
*/ | ||
static userProvidedPrivacyConsent(): Promise<boolean> { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return Promise.resolve(false); | ||
} | ||
/** | ||
* True if the application requires user privacy consent, false otherwise | ||
* @returns Promise<boolean> | ||
*/ | ||
static requiresUserPrivacyConsent(): Promise<boolean> { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return Promise.resolve(false); | ||
//returns a promise | ||
return RNOneSignal.userProvidedPrivacyConsent(); | ||
} | ||
//returns a promise | ||
return RNOneSignal.requiresUserPrivacyConsent(); | ||
/** | ||
* True if the application requires user privacy consent, false otherwise | ||
* @returns Promise<boolean> | ||
*/ | ||
static requiresUserPrivacyConsent(): Promise<boolean> { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return Promise.resolve(false); | ||
} | ||
/** | ||
* For GDPR users, your application should call this method before setting the App ID. | ||
* @param {boolean} required | ||
* @returns void | ||
*/ | ||
static setRequiresUserPrivacyConsent(required: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
//returns a promise | ||
return RNOneSignal.requiresUserPrivacyConsent(); | ||
} | ||
RNOneSignal.setRequiresUserPrivacyConsent(required); | ||
/** | ||
* For GDPR users, your application should call this method before setting the App ID. | ||
* @param {boolean} required | ||
* @returns void | ||
*/ | ||
static setRequiresUserPrivacyConsent(required: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* If your application is set to require the user's privacy consent, you can provide this consent using this method. | ||
* @param {boolean} granted | ||
* @returns void | ||
*/ | ||
static provideUserConsent(granted: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
RNOneSignal.setRequiresUserPrivacyConsent(required); | ||
} | ||
RNOneSignal.provideUserConsent(granted); | ||
/** | ||
* If your application is set to require the user's privacy consent, you can provide this consent using this method. | ||
* @param {boolean} granted | ||
* @returns void | ||
*/ | ||
static provideUserConsent(granted: boolean): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/* O T H E R F U N C T I O N S */ | ||
RNOneSignal.provideUserConsent(granted); | ||
} | ||
/** | ||
* Enable logging to help debug if you run into an issue setting up OneSignal. | ||
* @param {LogLevel} nsLogLevel - Sets the logging level to print to the Android LogCat log or Xcode log. | ||
* @param {LogLevel} visualLogLevel - Sets the logging level to show as alert dialogs. | ||
* @returns void | ||
*/ | ||
static setLogLevel(nsLogLevel: LogLevel, visualLogLevel: LogLevel): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
/* O T H E R F U N C T I O N S */ | ||
RNOneSignal.setLogLevel(nsLogLevel, visualLogLevel); | ||
/** | ||
* Enable logging to help debug if you run into an issue setting up OneSignal. | ||
* @param {LogLevel} nsLogLevel - Sets the logging level to print to the Android LogCat log or Xcode log. | ||
* @param {LogLevel} visualLogLevel - Sets the logging level to show as alert dialogs. | ||
* @returns void | ||
*/ | ||
static setLogLevel(nsLogLevel: LogLevel, visualLogLevel: LogLevel): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
/** | ||
* Clears all handlers and observers. | ||
* @returns void | ||
*/ | ||
static clearHandlers(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
eventManager.clearHandlers(); | ||
RNOneSignal.setLogLevel(nsLogLevel, visualLogLevel); | ||
} | ||
/** | ||
* Clears all handlers and observers. | ||
* @returns void | ||
*/ | ||
static clearHandlers(): void { | ||
if (!isNativeModuleLoaded(RNOneSignal)) { | ||
return; | ||
} | ||
eventManager.clearHandlers(); | ||
} | ||
} | ||
@@ -838,18 +1114,24 @@ | ||
export { | ||
ChangeEvent, | ||
PermissionChange, | ||
SubscriptionChange, | ||
EmailSubscriptionChange, | ||
SMSSubscriptionChange, | ||
NotificationReceivedEvent, | ||
OpenedEvent, | ||
InAppMessage, | ||
InAppMessageAction, | ||
InAppMessageLifecycleHandlerObject, | ||
OutcomeEvent, | ||
DeviceState, | ||
} | ||
ChangeEvent, | ||
PermissionChange, | ||
SubscriptionChange, | ||
EmailSubscriptionChange, | ||
SMSSubscriptionChange, | ||
NotificationReceivedEvent, | ||
OpenedEvent, | ||
InAppMessage, | ||
InAppMessageAction, | ||
InAppMessageLifecycleHandlerObject, | ||
OutcomeEvent, | ||
DeviceState, | ||
}; | ||
export { default as OSNotification } from './OSNotification'; | ||
export { OpenedEventAction, OpenedEventActionType } from './models/NotificationEvents'; | ||
export { IosPermissionStatus, ObserverChangeEvent } from './models/Subscription'; | ||
export { | ||
OpenedEventAction, | ||
OpenedEventActionType, | ||
} from './models/NotificationEvents'; | ||
export { | ||
IosPermissionStatus, | ||
ObserverChangeEvent, | ||
} from './models/Subscription'; |
export interface InAppMessage { | ||
messageId : string | ||
messageId: string; | ||
} | ||
export interface InAppMessageAction { | ||
closes_message : boolean; | ||
first_click : boolean; | ||
click_name ?: string; | ||
click_url ?: string; | ||
outcomes ?: object[]; | ||
tags ?: object; | ||
closes_message: boolean; | ||
first_click: boolean; | ||
click_name?: string; | ||
click_url?: string; | ||
outcomes?: object[]; | ||
tags?: object; | ||
} | ||
export interface InAppMessageLifecycleHandlerObject { | ||
onWillDisplayInAppMessage ?: (message: InAppMessage) => void; | ||
onDidDisplayInAppMessage ?: (message: InAppMessage) => void; | ||
onWillDismissInAppMessage ?: (message: InAppMessage) => void; | ||
onDidDismissInAppMessage ?: (message: InAppMessage) => void; | ||
onWillDisplayInAppMessage?: (message: InAppMessage) => void; | ||
onDidDisplayInAppMessage?: (message: InAppMessage) => void; | ||
onWillDismissInAppMessage?: (message: InAppMessage) => void; | ||
onDidDismissInAppMessage?: (message: InAppMessage) => void; | ||
} |
@@ -1,2 +0,2 @@ | ||
import OSNotification from "../OSNotification"; | ||
import OSNotification from '../OSNotification'; | ||
@@ -7,8 +7,8 @@ // 0 = NotificationClicked, 1 = ButtonClicked | ||
export interface OpenedEvent { | ||
action : OpenedEventAction; | ||
notification : OSNotification; | ||
action: OpenedEventAction; | ||
notification: OSNotification; | ||
} | ||
export interface OpenedEventAction { | ||
type : OpenedEventActionType | ||
type: OpenedEventActionType; | ||
} |
export interface OutcomeEvent { | ||
session : string; | ||
id : string; | ||
timestamp : number; | ||
weight : number; | ||
notification_ids: string[]; | ||
session: string; | ||
id: string; | ||
timestamp: number; | ||
weight: number; | ||
notification_ids: string[]; | ||
} |
@@ -6,15 +6,15 @@ // 0 = NotDetermined, 1 = Denied, 2 = Authorized, 3 = Provisional, 4 = Ephemeral | ||
export interface DeviceState { | ||
userId : string; | ||
pushToken : string; | ||
emailUserId : string; | ||
emailAddress : string; | ||
smsUserId : string; | ||
smsNumber : string; | ||
isSubscribed : boolean; | ||
isPushDisabled : boolean; | ||
isEmailSubscribed : boolean; | ||
isSMSSubscribed : boolean; | ||
hasNotificationPermission ?: boolean; // is areNotificationsEnabled on android | ||
notificationPermissionStatus ?: IosPermissionStatus; // ios only | ||
// areNotificationsEnabled (android) not included since it is converted to hasNotificationPermission in bridge | ||
userId: string; | ||
pushToken: string; | ||
emailUserId: string; | ||
emailAddress: string; | ||
smsUserId: string; | ||
smsNumber: string; | ||
isSubscribed: boolean; | ||
isPushDisabled: boolean; | ||
isEmailSubscribed: boolean; | ||
isSMSSubscribed: boolean; | ||
hasNotificationPermission?: boolean; // is areNotificationsEnabled on android | ||
notificationPermissionStatus?: IosPermissionStatus; // ios only | ||
// areNotificationsEnabled (android) not included since it is converted to hasNotificationPermission in bridge | ||
} | ||
@@ -24,32 +24,36 @@ | ||
export interface ChangeEvent<ObserverChangeEvent> { | ||
from : ObserverChangeEvent; | ||
to : ObserverChangeEvent; | ||
from: ObserverChangeEvent; | ||
to: ObserverChangeEvent; | ||
} | ||
export type ObserverChangeEvent = PermissionChange | SubscriptionChange | EmailSubscriptionChange | SMSSubscriptionChange | ||
export type ObserverChangeEvent = | ||
| PermissionChange | ||
| SubscriptionChange | ||
| EmailSubscriptionChange | ||
| SMSSubscriptionChange; | ||
export interface PermissionChange { | ||
status ?: IosPermissionStatus; // ios | ||
hasPrompted ?: boolean; // ios | ||
provisional ?: boolean; // ios | ||
areNotificationsEnabled ?: boolean; // android | ||
status?: IosPermissionStatus; // ios | ||
hasPrompted?: boolean; // ios | ||
provisional?: boolean; // ios | ||
areNotificationsEnabled?: boolean; // android | ||
} | ||
export interface SubscriptionChange { | ||
userId ?: string; | ||
pushToken ?: string; | ||
isSubscribed : boolean; | ||
isPushDisabled : boolean; | ||
userId?: string; | ||
pushToken?: string; | ||
isSubscribed: boolean; | ||
isPushDisabled: boolean; | ||
} | ||
export interface EmailSubscriptionChange { | ||
emailAddress ?: string; | ||
emailUserId ?: string; | ||
isEmailSubscribed : boolean; | ||
emailAddress?: string; | ||
emailUserId?: string; | ||
isEmailSubscribed: boolean; | ||
} | ||
export interface SMSSubscriptionChange { | ||
smsNumber ?: string; | ||
smsUserId ?: string; | ||
isSMSSubscribed : boolean; | ||
smsNumber?: string; | ||
smsUserId?: string; | ||
isSMSSubscribed: boolean; | ||
} |
import { Platform } from 'react-native'; | ||
export default class OSNotification { | ||
body : string; | ||
sound ?: string; | ||
title ?: string; | ||
launchURL ?: string; | ||
rawPayload : object | string; // platform bridges return different types | ||
actionButtons ?: object[]; | ||
additionalData ?: object; | ||
notificationId : string; | ||
// android only | ||
groupKey ?: string; | ||
groupMessage ?: string; | ||
ledColor ?: string; | ||
priority ?: number; | ||
smallIcon ?: string; | ||
largeIcon ?: string; | ||
bigPicture ?: string; | ||
collapseId ?: string; | ||
fromProjectNumber ?: string; | ||
smallIconAccentColor ?: string; | ||
lockScreenVisibility ?: string; | ||
androidNotificationId ?: number; | ||
// ios only | ||
badge ?: string; | ||
badgeIncrement ?: string; | ||
category ?: string; | ||
threadId ?: string; | ||
subtitle ?: string; | ||
templateId ?: string; | ||
templateName ?: string; | ||
attachments ?: object; | ||
mutableContent ?: boolean; | ||
contentAvailable ?: string; | ||
relevanceScore ?: number; | ||
interruptionLevel ?: string; | ||
body: string; | ||
sound?: string; | ||
title?: string; | ||
launchURL?: string; | ||
rawPayload: object | string; // platform bridges return different types | ||
actionButtons?: object[]; | ||
additionalData?: object; | ||
notificationId: string; | ||
// android only | ||
groupKey?: string; | ||
groupMessage?: string; | ||
ledColor?: string; | ||
priority?: number; | ||
smallIcon?: string; | ||
largeIcon?: string; | ||
bigPicture?: string; | ||
collapseId?: string; | ||
fromProjectNumber?: string; | ||
smallIconAccentColor?: string; | ||
lockScreenVisibility?: string; | ||
androidNotificationId?: number; | ||
// ios only | ||
badge?: string; | ||
badgeIncrement?: string; | ||
category?: string; | ||
threadId?: string; | ||
subtitle?: string; | ||
templateId?: string; | ||
templateName?: string; | ||
attachments?: object; | ||
mutableContent?: boolean; | ||
contentAvailable?: string; | ||
relevanceScore?: number; | ||
interruptionLevel?: string; | ||
constructor(receivedEvent: OSNotification) { | ||
this.body = receivedEvent.body; | ||
this.sound = receivedEvent.sound; | ||
this.title = receivedEvent.title; | ||
this.launchURL = receivedEvent.launchURL; | ||
this.rawPayload = receivedEvent.rawPayload; | ||
this.actionButtons = receivedEvent.actionButtons; | ||
this.additionalData = receivedEvent.additionalData; | ||
this.notificationId = receivedEvent.notificationId; | ||
constructor(receivedEvent: OSNotification) { | ||
this.body = receivedEvent.body; | ||
this.sound = receivedEvent.sound; | ||
this.title = receivedEvent.title; | ||
this.launchURL = receivedEvent.launchURL; | ||
this.rawPayload = receivedEvent.rawPayload; | ||
this.actionButtons = receivedEvent.actionButtons; | ||
this.additionalData = receivedEvent.additionalData; | ||
this.notificationId = receivedEvent.notificationId; | ||
if (Platform.OS === 'android') { | ||
this.groupKey = receivedEvent.groupKey; | ||
this.ledColor = receivedEvent.ledColor; | ||
this.priority = receivedEvent.priority; | ||
this.smallIcon = receivedEvent.smallIcon; | ||
this.largeIcon = receivedEvent.largeIcon; | ||
this.bigPicture = receivedEvent.bigPicture; | ||
this.collapseId = receivedEvent.collapseId; | ||
this.groupMessage = receivedEvent.groupMessage; | ||
this.fromProjectNumber = receivedEvent.fromProjectNumber; | ||
this.smallIconAccentColor = receivedEvent.smallIconAccentColor; | ||
this.lockScreenVisibility = receivedEvent.lockScreenVisibility; | ||
this.androidNotificationId = receivedEvent.androidNotificationId; | ||
} | ||
if (Platform.OS === 'android') { | ||
this.groupKey = receivedEvent.groupKey; | ||
this.ledColor = receivedEvent.ledColor; | ||
this.priority = receivedEvent.priority; | ||
this.smallIcon = receivedEvent.smallIcon; | ||
this.largeIcon = receivedEvent.largeIcon; | ||
this.bigPicture = receivedEvent.bigPicture; | ||
this.collapseId = receivedEvent.collapseId; | ||
this.groupMessage = receivedEvent.groupMessage; | ||
this.fromProjectNumber = receivedEvent.fromProjectNumber; | ||
this.smallIconAccentColor = receivedEvent.smallIconAccentColor; | ||
this.lockScreenVisibility = receivedEvent.lockScreenVisibility; | ||
this.androidNotificationId = receivedEvent.androidNotificationId; | ||
} | ||
if (Platform.OS === 'ios') { | ||
this.badge = receivedEvent.badge; | ||
this.category = receivedEvent.category; | ||
this.threadId = receivedEvent.threadId; | ||
this.subtitle = receivedEvent.subtitle; | ||
this.templateId = receivedEvent.templateId; | ||
this.attachments = receivedEvent.attachments; | ||
this.templateName = receivedEvent.templateName; | ||
this.mutableContent = receivedEvent.mutableContent; | ||
this.badgeIncrement = receivedEvent.badgeIncrement; | ||
this.contentAvailable = receivedEvent.contentAvailable; | ||
this.relevanceScore = receivedEvent.relevanceScore; | ||
this.interruptionLevel = receivedEvent.interruptionLevel; | ||
} | ||
if (Platform.OS === 'ios') { | ||
this.badge = receivedEvent.badge; | ||
this.category = receivedEvent.category; | ||
this.threadId = receivedEvent.threadId; | ||
this.subtitle = receivedEvent.subtitle; | ||
this.templateId = receivedEvent.templateId; | ||
this.attachments = receivedEvent.attachments; | ||
this.templateName = receivedEvent.templateName; | ||
this.mutableContent = receivedEvent.mutableContent; | ||
this.badgeIncrement = receivedEvent.badgeIncrement; | ||
this.contentAvailable = receivedEvent.contentAvailable; | ||
this.relevanceScore = receivedEvent.relevanceScore; | ||
this.interruptionLevel = receivedEvent.interruptionLevel; | ||
} | ||
} | ||
} |
@@ -10,4 +10,6 @@ { | ||
], | ||
"rootDir": "src", | ||
"declaration": true, | ||
"allowSyntheticDefaultImports": true, | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
@@ -14,0 +16,0 @@ "strict": true, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
113
6549
1
839229
7
1