iOS React Native Bridge Implementation

📘

Objective

To provide a React Native App Developer with details on how to implement the React Native Bridge to enable communication between React Native and the iOS Bubbl Plugin.

📘

Audience

React Native App Developer

To implement the React Native Bridge, add the following code under the project ios/ folder.

886 1414 1274

Replace the default file content as follows:

#ifndef BubblSdk_h
#define BubblSdk_h

#import <React/RCTBridgeModule.h>

@interface BubblSdk : NSObject <RCTBridgeModule>
@end

#endif /* BubblSdk_h */
886 1466 1462 1176
#import <Foundation/Foundation.h>

#import "BubblSdk.h"
#import <Bubbl/Bubbl.h>

@implementation BubblSdk


RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(saveBubblId:(NSString *)bubblId)
{
  dispatch_async(dispatch_get_main_queue(), ^{
    [BUMain setXBubblID:(NSString *)bubblId];
  });

}

RCT_EXPORT_METHOD(saveActivatedPayloadTitle:(NSString *)activatedViewTitle)
{
  dispatch_async(dispatch_get_main_queue(), ^{
    [BUMain setActivatedPayloadTitle:(NSString *)activatedViewTitle];
  });

}

RCT_EXPORT_METHOD(initialize:(NSString *)apiUrl apiKey:(NSString *)apiKey)
{
  dispatch_async(dispatch_get_main_queue(), ^{
    [BUMain setupWithKey:apiKey withURLString:apiUrl withAppGroup: @"<APP GROUP HERE>"];
  });
}

RCT_EXPORT_METHOD(displayPrivacyOptions)
{
  dispatch_async(dispatch_get_main_queue(), ^{
    [BUMain displayPrivacyOptions];
  });
}

RCT_EXPORT_METHOD(displayActivatedPayloads)
{
  dispatch_async(dispatch_get_main_queue(), ^{
    [BUMain.sharedInstance displayActivatedPayloads];
  });
}

RCT_EXPORT_METHOD(displayDataPayloads)
{
  dispatch_async(dispatch_get_main_queue(), ^{
    [BUMain.sharedInstance displayDebugCampaignsView];
  });
}

RCT_EXPORT_METHOD(displayLogs)
{
  dispatch_async(dispatch_get_main_queue(), ^{
    [BUMain.sharedInstance displayDebugConsoleView];
  });
}

RCT_EXPORT_METHOD(saveSegmentationTags:(NSString *)tags)
{
  dispatch_async(dispatch_get_main_queue(), ^{
    [BUMain setXBSegs:(NSString *)tags];
  });

}

RCT_REMAP_METHOD(getSegmentationTags, resolver: (RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject)
{
  dispatch_async(dispatch_get_main_queue(), ^{
    resolve([BUMain getXBSegs]);
  });

}

@end