Appfigurate™️
HomeDocumentation
  • Introducing Appfigurate™️ 3
  • Getting Started
    • Getting Started
    • Examples
    • Upgrade guide
      • v1.4.0 to v2.2.0
      • v2.1.1 to v2.2.0
      • v2.2.1 to v3.0.0
      • v3.2.1 to v4.0.0
    • iOS native app integration
      • iOS app extension integration
    • watchOS app integration
      • watchOS app extension integration
    • Android native app integration
    • Mobile Flutter integration
      • Flutter iOS
      • Flutter Android
    • React Native integration
      • iOS native module integration
      • Android native module integration
      • JavaScript integration
    • Third party remote configuration providers
      • Firebase Remote Config
      • Launch Darkly
      • Other third party remote configuration providers
  • Configuration subclasses
    • Supported property types
      • Boolean
      • Integer
      • Float
      • Double
      • Plain String
      • Encrypted String
    • Custom executable actions
    • Slider icon types
  • Additional reading
    • Info.plist options
    • AndroidManifest.xml options
    • Displaying overridden configuration
    • Security
      • Best practice
      • Encryption
      • Export compliance
      • App Store compliance
      • PrivacyInfo.xcprivacy
      • Rotating your private key
  • Automation testing
    • iOS native app automation testing
    • Android native automation testing
  • API
    • iOS and watchOS API
    • Android API
    • Mobile Flutter API
    • React Native API
  • Appfigurate User Guide
    • Introduction
    • Main menu
    • Select app
    • Add app
    • Import app
    • Install example apps
    • Settings
      • Passcode Lock
      • Restore
      • Backup
      • Delete all apps and Settings
      • Analytics
    • Edit app
    • Configure app
    • Permissions
  • Appfigurate SE user guide
    • Introduction
    • Manual encryption
      • ENCRYPTED_STRING macro/function
      • ENCRYPTED_STRING_IOS_WATCHOS macro/function
    • Setup iOS Simulator app
    • Setup Android Emulator app
    • Xcode source editor extension
      • Troubleshooting
    • Real device cloud testing services
      • BrowserStack
  • LEGAL
    • License Agreement
    • Privacy Policy
    • Release History
    • Third party notices
Powered by GitBook
On this page
  1. Getting Started
  2. React Native integration

iOS native module integration

In your Xcode project create a new Objective-C class named RCTAppfiguratePlugin.

Example RCTAppfiguratePlugin.h header file

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>

NS_ASSUME_NONNULL_BEGIN

@interface RCTAppfigurateModule : RCTEventEmitter<RCTBridgeModule>
@end

NS_ASSUME_NONNULL_END

Example RCTAppfiguratePlugin.m implementation file

#import "RCTAppfigurateModule.h"
@import AppfigurateLibrary;

@interface APLConfiguration ()
- (NSDictionary*) dictionaryFromConfiguration;
@end

@implementation RCTAppfigurateModule {
  NSDictionary* cachedConfiguration;
  BOOL observing;
}

RCT_EXPORT_MODULE();

- (instancetype) init {
  self = [super init];
  if (self) {
    cachedConfiguration = [[APLConfiguration sharedConfiguration] dictionaryFromConfiguration];
    APLAddConfigurationUpdatedBlock(^(NSNotification* notification) {
      self->cachedConfiguration = [[APLConfiguration sharedConfiguration] dictionaryFromConfiguration];
      if (self->observing) {
        NSObject* action = notification.userInfo[APLConfigurationUpdatedAction];
        if (action == nil) {
          action = [NSNull null];
        }
        [self sendEventWithName: @"APLConfigurationUpdated" body:
          @{@"APLConfigurationUpdatedAction": action}];
      }
    });
  }
  return self;
}

RCT_EXPORT_METHOD(nativeValue: (NSString*) propertyName resolver: (RCTPromiseResolveBlock) resolve rejecter: (RCTPromiseRejectBlock) reject) {
  resolve([cachedConfiguration objectForKey: propertyName]);
}

RCT_EXPORT_METHOD(description: (RCTPromiseResolveBlock) resolve rejecter: (RCTPromiseRejectBlock) reject) {
  resolve([[APLConfiguration sharedConfiguration] description]);
}

RCT_EXPORT_METHOD(modifications: (RCTPromiseResolveBlock) resolve rejecter: (RCTPromiseRejectBlock) reject) {
  resolve([[APLConfiguration sharedConfiguration] modifications]);
}

RCT_EXPORT_METHOD(version: (RCTPromiseResolveBlock) resolve rejecter: (RCTPromiseRejectBlock) reject) {
  resolve(APLVersion());
}

RCT_EXPORT_METHOD(setLogging: (BOOL) logging resolve: (RCTPromiseResolveBlock) resolve rejecter: (RCTPromiseRejectBlock) reject) {
  APLSetLogging(logging);
  resolve(nil);
}

RCT_EXPORT_METHOD(saveConfiguration: (RCTPromiseResolveBlock) resolve rejecter: (RCTPromiseRejectBlock) reject) {
  APLSaveConfiguration();
  resolve(nil);
}

RCT_EXPORT_METHOD(restoreConfiguration: (RCTPromiseResolveBlock) resolve rejecter: (RCTPromiseRejectBlock) reject) {
  APLRestoreConfiguration();
  resolve(nil);
}

- (void) startObserving {
  observing = YES;
}

- (void) stopObserving {
  observing = NO;
}

- (NSArray<NSString*>*) supportedEvents {
  return @[@"APLConfigurationUpdated"];
}

@end
PreviousReact Native integrationNextAndroid native module integration

Last updated 5 months ago

The iOS native module is now integrated. Now jump to .

Android native module integration