react-native-onesignal
Advanced tools
Comparing version 3.2.14 to 3.3.0
149
index.js
@@ -9,14 +9,33 @@ | ||
const OS_REMOTE_NOTIFICATION_RECEIVED = 'OneSignal-remoteNotificationReceived'; | ||
const OS_REMOTE_NOTIFICATION_OPENED = 'OneSignal-remoteNotificationOpened'; | ||
const OS_IDS_AVAILABLE = 'OneSignal-idsAvailable'; | ||
const OS_EMAIL_SUBSCRIPTION = 'OneSignal-emailSubscription'; | ||
const OS_IN_APP_MESSAGE_CLICKED = 'OneSignal-inAppMessageClicked'; | ||
const eventBroadcastNames = [ | ||
'OneSignal-remoteNotificationReceived', | ||
'OneSignal-remoteNotificationOpened', | ||
'OneSignal-idsAvailable', | ||
'OneSignal-emailSubscription' | ||
OS_REMOTE_NOTIFICATION_RECEIVED, | ||
OS_REMOTE_NOTIFICATION_OPENED, | ||
OS_IDS_AVAILABLE, | ||
OS_EMAIL_SUBSCRIPTION, | ||
OS_IN_APP_MESSAGE_CLICKED | ||
]; | ||
const NOTIFICATION_RECEIVED_EVENT = "received"; | ||
const NOTIFICATION_OPENED_EVENT = "opened"; | ||
const IDS_AVAILABLE_EVENT = "ids"; | ||
const EMAIL_SUBSCRIPTION_EVENT = "emailSubscription"; | ||
const IN_APP_MESSAGE_CLICKED_EVENT = "inAppMessageClicked"; | ||
const _eventNames = [ | ||
NOTIFICATION_RECEIVED_EVENT, | ||
NOTIFICATION_OPENED_EVENT, | ||
IDS_AVAILABLE_EVENT, | ||
EMAIL_SUBSCRIPTION_EVENT, | ||
IN_APP_MESSAGE_CLICKED_EVENT | ||
]; | ||
var oneSignalEventEmitter; | ||
var _eventNames = [ "received", "opened", "ids", "emailSubscription"]; | ||
var _notificationHandler = new Map(); | ||
var _eventTypeHandler = new Map(); | ||
var _notificationCache = new Map(); | ||
@@ -41,3 +60,3 @@ var _listeners = []; | ||
// Cache the result first if we have not. | ||
var handler = _notificationHandler.get(type); | ||
var handler = _eventTypeHandler.get(type); | ||
@@ -61,15 +80,28 @@ if (handler) { | ||
// Listen to events of notification received, opened, device registered and IDSAvailable. | ||
// Listen to events of notification received, opened, device registered, IDSAvailable, and IAMClicked. | ||
invariant( | ||
type === 'received' || type === 'opened' || type === 'ids' || type == 'emailSubscription', | ||
'OneSignal only supports `received`, `opened`, and `ids` events' | ||
type === NOTIFICATION_RECEIVED_EVENT || | ||
type === NOTIFICATION_OPENED_EVENT || | ||
type === IDS_AVAILABLE_EVENT || | ||
type === EMAIL_SUBSCRIPTION_EVENT || | ||
type === IN_APP_MESSAGE_CLICKED_EVENT, | ||
'OneSignal only supports `received`, `opened`, `ids`, `emailSubscription`, and `inAppMessageClicked` events' | ||
); | ||
_notificationHandler.set(type, handler); | ||
_eventTypeHandler.set(type, handler); | ||
if (type == 'opened') { | ||
RNOneSignal.didSetNotificationOpenedHandler(); | ||
if (type === NOTIFICATION_OPENED_EVENT) { | ||
RNOneSignal.initNotificationOpenedHandlerParams(); | ||
} | ||
// triggers ids event | ||
if (type === IDS_AVAILABLE_EVENT) { | ||
RNOneSignal.configure(); | ||
} | ||
if (type === IN_APP_MESSAGE_CLICKED_EVENT) { | ||
RNOneSignal.initInAppMessageClickHandlerParams(); | ||
} | ||
// Check if there is a cache for this type of event | ||
@@ -87,7 +119,11 @@ var cache = _notificationCache.get(type); | ||
invariant( | ||
type === 'received' || type === 'opened' || type === 'ids' || type == 'emailSubscription', | ||
'OneSignal only supports `received`, `opened`, and `ids` events' | ||
type === NOTIFICATION_RECEIVED_EVENT || | ||
type === NOTIFICATION_OPENED_EVENT || | ||
type === IDS_AVAILABLE_EVENT || | ||
type === EMAIL_SUBSCRIPTION_EVENT || | ||
type === IN_APP_MESSAGE_CLICKED_EVENT, | ||
'OneSignal only supports `received`, `opened`, `ids`, `emailSubscription`, and `inAppMessageClicked` events' | ||
); | ||
_notificationHandler.delete(type); | ||
_eventTypeHandler.delete(type); | ||
} | ||
@@ -151,6 +187,5 @@ | ||
/* deprecated */ | ||
static configure() { | ||
if (!checkIfInitialized()) return; | ||
RNOneSignal.configure(); | ||
console.warn("OneSignal: the `configure` method has been deprecated. The `ids` event is now triggered automatically."); | ||
} | ||
@@ -161,3 +196,3 @@ | ||
if (Platform.OS == 'ios') { | ||
if (Platform.OS === 'ios') { | ||
RNOneSignal.initWithAppId(appId, iOSSettings); | ||
@@ -381,2 +416,72 @@ } else { | ||
} | ||
} | ||
/** | ||
* Pass a String key and any value and creates a trigger map to pass to addTriggers() | ||
*/ | ||
static addTrigger(key, value) { | ||
if (!checkIfInitialized()) return; | ||
var trigger = {}; | ||
trigger[key] = value; | ||
if (Platform.OS === 'android') { | ||
RNOneSignal.addTriggers(trigger); | ||
} else { | ||
console.log("This function is not yet implemented on iOS"); | ||
} | ||
} | ||
/** | ||
* Expected format is Map<String, Object>, make sure all values are Objects and keys are Strings | ||
*/ | ||
static addTriggers(triggers) { | ||
if (!checkIfInitialized()) return; | ||
if (Platform.OS === 'android') { | ||
RNOneSignal.addTriggers(triggers); | ||
} else { | ||
console.log("This function is not yet implemented on iOS"); | ||
} | ||
} | ||
static removeTriggersForKeys(keys) { | ||
if (!checkIfInitialized()) return; | ||
if (Platform.OS === 'android') { | ||
RNOneSignal.removeTriggersForKeys(keys); | ||
} else { | ||
console.log("This function is not yet implemented on iOS"); | ||
} | ||
} | ||
static removeTriggerForKey(key) { | ||
if (!checkIfInitialized()) return; | ||
if (Platform.OS === 'android') { | ||
RNOneSignal.removeTriggerForKey(key); | ||
} else { | ||
console.log("This function is not yet implemented on iOS"); | ||
} | ||
} | ||
static getTriggerValueForKey(key) { | ||
if (!checkIfInitialized()) return; | ||
// returns promise | ||
if (Platform.OS === 'android') { | ||
return RNOneSignal.getTriggerValueForKey(key); | ||
} else { | ||
console.log("This function is not yet implemented on iOS"); | ||
} | ||
} | ||
static pauseInAppMessages(pause) { | ||
if (!checkIfInitialized()) return; | ||
if (Platform.OS === 'android') { | ||
RNOneSignal.pauseInAppMessages(pause); | ||
} else { | ||
console.log("This function is not yet implemented on iOS"); | ||
} | ||
} | ||
} |
{ | ||
"name": "react-native-onesignal", | ||
"version": "3.2.14", | ||
"version": "3.3.0", | ||
"description": "React Native OneSignal Component", | ||
@@ -12,7 +12,2 @@ "main": "index", | ||
}, | ||
"rnpm": { | ||
"ios": { | ||
"sourceDir": "./ios" | ||
} | ||
}, | ||
"keywords": [ | ||
@@ -19,0 +14,0 @@ "react-component", |
@@ -12,4 +12,2 @@ <p align="center"> | ||
 | ||
#### Installation | ||
@@ -22,3 +20,3 @@ See the [Setup Guide](https://documentation.onesignal.com/v5.0/docs/react-native-sdk-setup) for setup instructions. | ||
#### Support | ||
Please visit this repository's [Github issue tracker](https://github.com/geektimecoil/react-native-onesignal/issues) for feature requests and bug reports related specificly to the SDK. | ||
Please visit this repository's [Github issue tracker](https://github.com/geektimecoil/react-native-onesignal/issues) for feature requests and bug reports related specifically to the SDK. | ||
For account issues and support please contact OneSignal support from the [OneSignal.com](https://onesignal.com) dashboard. | ||
@@ -30,3 +28,3 @@ | ||
#### Supports: | ||
* Tested from iOS 7 to iOS 11.3 | ||
* Tested from Android 4.0.3 (API level 15) to Android 8.1 (27) | ||
* Tested from iOS 7 to iOS 12.3 | ||
* Tested from Android 4.0.3 (API level 15) to Android 9 (28) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
14741085
981
27