# iOS native module integration

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

> Example `RCTAppfiguratePlugin.h` header file

```objectivec
#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

```objectivec
#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 [JavaScript integration](/getting-started/react-native-integration/javascript-integration.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.electricbolt.co.nz/getting-started/react-native-integration/ios-native-module-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
