Initialise React Native
Before you can use APIs from the react-native-hydra-lib
package, ensure the Hydra SDK is initialized successfully.
To initialize Hydra SDK for React Native, follow these steps:
-
Register for the SDK initialization event to get the callback when the SDK's initialization succeeds or fails. Use the to the Get callback for Hydra SDK initialization result API to register.
-
Use the HydraCore class for user management. It includes static functions such as: signUp and signIn. These functions require a customerId that must match the configuration on the Capillary CRM dashboard.
-
Use the signUp function to register the user. For subsequent launches, use signIn.
-
The HydraPushNotification class provides static functions for push notifications: requestPermission and getFCMToken. To receive push notifications, you can ask for permission using requestPermission.
-
Use getFCMToken to get the FCM token. You can also add the listener using addTokenAvailableListener API in HydraNativeEventEmitter to get it when it is available.
-
The HydraCore class includes additional functions:
- Use updateUser to update the userDetails set in signUp or signIn API.
- Use signOut to sign out a user.
- Use updateGeoConfig to update users geo configuration such as city, country and countryCode.
- Use updatePushPreferences to update push notification preferences and enable or disable promotional and transactional push notifications.
- Use reportUserEvent to report a custom user event to help analyze users' behavior patterns.
-
Use the HydraInbox class to manage them with functions like getInboxMessages, getUnreadMessagesCount, markInboxMessageAsRead, deleteInboxMessage, and deleteAllInboxMessages. The Hydra SDK has a database of the hydra notifications and doesn't save any non hydra notifications. These APIs allow you to implement your own UI for Notification Center.
-
Use the HydraInboxUI class functions: showNotificationCenter and hideNotificationCenterIfShowing to use the built-in notification center from the Hydra plugin.
-
The HydraNativeEventEmitter class allows you to register listeners for different events from SDK.
- Use getInstance API to get the singleton instance.
- Use addHydraNotificationReceivedListener when a Hydra notification is received.
- Use addHydraNotificationClickedListener to receive a callback when a hydra push notification is clicked, an InApp message is clicked, or a notification is clicked in hydra built-in notification center.
- Use addHydraNotificationShownListener to receive callback when a hydra notification is shown using notification preview.
- Use addHydraNotificationDismissedListener when a hydra notification is dismissed by the user.
- Use addNotificationCenterDismissedListener to get the callback when hydra in-built notification center is dismissed by the user.
- Use addInboxUpdatedListener when the hydra notification database is updated.
- Use removeListener API to remove a listener.
-
Configure log levels in
hydra-config.json
for Android and inHydraConfig.plist
for iOS. Console log level is used for logging in xCode console and LogCat logs for iOS and Android respectively. Remote log level is used to save the logs in the backend. Both logs have to be integer between 0 to 5, where 0 turns off the logs and 5 is verbose. Use the LOG_LEVELS key on iOS and log_levels to configure iOS and Android logs respectively.
Updated 5 days ago