iOS native module integration

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

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

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

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

Last updated