react-native-gimbal
v1.0.0
Published
React Native module for Gimbal SDK
Downloads
1
Readme
react-native-gimbal
Installation
Clone github.com/PaeDae/react-native-gimbal-sdk
.
Run npm pack
from the repo directory to produce a .tz file.
Unzip the .tz and rename the contained directory as desired.
Add this directory as a library to your React-Native project by running yarn add [directory path]
from your project directory.
If you are using create-react-app
, you must eject the app to expose native code.
If you are using Expo, you must run exp detach
to expose native code.
Android:
In MainApplication.java
, add:
import com.gimbal.android.Gimbal;
- In
MainApplication
classprivate static final String GIMBAL_APP_API_KEY = "YOUR GIMBAL API KEY HERE";
- In
onCreate()
methodGimbal.setApiKey(this, GIMBAL_APP_API_KEY);
iOS:
In AppDelegate.m
, add:
#import <Gimbal/Gimbal.h>
- In
didFinishLaunchingWithOptions
method:[Gimbal setAPIKey:@"YOUR GIMBAL API KEY HERE" options:nil];
Extra steps needed on React Native v0.60+:cd ios && pod install && cd ..
To use communicates, extra implementation steps are required in native Objective-C, most likely in AppDelegate.m
. First, obtain a reference to the CommunicationManager
and assign a delegate to UNUserNotificationCenter
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
_communicationManagerModule = [bridge moduleForName:@"CommunicationManager"];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
...
}
Then implement UNUserNotificationCenterDelegate.didReceiveNotificationResponse
:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
if (_communicationManagerModule == nil) {
return;
}
SEL handleResponseSelector = NSSelectorFromString(@"handleNotificationResponse:completionHandler:");
if ([_communicationManagerModule respondsToSelector:handleResponseSelector]) {
IMP handleResponseImplementation = [_communicationManagerModule methodForSelector:handleResponseSelector];
CGRect (*handleResponseFunction)(id, SEL, UNNotificationResponse*, void (^)(void)) = (void *)handleResponseImplementation;
handleResponseFunction(_communicationManagerModule, handleResponseSelector, response, completionHandler);
}
}
To run the app:
- Android:
yarn react-native run-android
ornpx react-native run-android
- iOS:
yarn react-native run-ios
ornpx react-native run-ios
Troubleshoot
If you encounter this error: Unsupported class file major version 57.
It could be that JDK version 13 does not work well with React Native 0.60+. Use JDK 11.
API
Gimbal
// start the Gimbal module:
Gimbal.start();
// check status:
Gimbal.isStarted();
// get the application ID:
Gimbal.getApplicationInstanceIdentifier();
// stop the Gimbal SDK:
Gimbal.stop();
PrivacyManager
PrivacyManager.getGdprConsentRequirement();
PrivacyManager.setUserConsent(PrivacyManager.GDPR_CONSENT_TYPE_PLACES, stateValue);
PrivacyManager.getUserConsent(PrivacyManager.GDPR_CONSENT_TYPE_PLACES);
PlaceManager
PlaceManager.startMonitoring();
PlaceManager.stopMonitoring();
PlaceManager.isMonitoring();
// event types:
'VisitStart'
'VisitStartWithDelay'
'VisitEnd'
'BeaconSighting'
'LocationDetected'
GimbalDebugger
GimbalDebugger.enableBeaconSightingsLogging();
GimbalDebugger.disableBeaconSightingsLogging();
GimbalDebugger.isBeaconSightingsLoggingEnabled();
GimbalDebugger.enableDebugLogging();
GimbalDebugger.disableDebugLogging();
GimbalDebugger.isDebugLoggingEnabled();
GimbalDebugger.enablePlaceLogging();
GimbalDebugger.disablePlaceLogging();
GimbalDebugger.isPlaceLoggingEnabled();
CommunicationManager
CommunicationManager.startReceivingCommunications();
CommunicationManager.stopReceivingCommunications();
CommunicationManager.isReceivingCommunications();
//Only Android:
CommunicationManager.setNotificationChannelId("");
CommunicationManager.getNotificationChannelId();
Communicationmanager.handleNotificationResponse();
// event types:
'PrepareCommunicationForDisplay'
'PresentNotificationForCommunications'
'NotificationClicked'