1.0.0 • Published 2 years ago

react-native-gimbal v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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: 1. import com.gimbal.android.Gimbal; 1. In MainApplication class private static final String GIMBAL_APP_API_KEY = "YOUR GIMBAL API KEY HERE"; 1. In onCreate() method Gimbal.setApiKey(this, GIMBAL_APP_API_KEY);

iOS:

In AppDelegate.m, add: 1. #import <Gimbal/Gimbal.h> 1. 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 or npx react-native run-android
  • iOS: yarn react-native run-ios or npx 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'