Having trouble setting up app.config.ts to make changes to AppDelegate.m

Please provide the following:

  1. SDK Version: 45.0.0
  2. Platform: iOS

Hi everyone! I am trying to build a config plugin to make changes to AppDelegate.m while staying in managed. I want to make changes to AppDelegate.m to implement the FourSquare Pilgrim SDK, which requires to accept background location and to make changes to the didFinishLaunchingWithOptions function in AppDelegate.m.

This is my app.config.ts:

import { ExpoConfig } from '@expo/config';
import { withAppDelegate, ConfigPlugin, WarningAggregator } from '@expo/config-plugins';

const config = { 
}

const RN_PILGRIM_DID_FINISH_LAUNCHING_IDENTIFIER = `- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{`

const RN_PILGRIM_DID_FINISH_LAUNCHING_CODE = `
[[FSQPPilgrimManager sharedManager] configureWithConsumerKey:@"KEY"
    secret:@"SECRET"
    delegate:nil
completion:nil];
`

function modifyAppDelegate(appDelegate: string) {
  console.log("modifyAppDelegate");
    if (appDelegate.includes(RN_PILGRIM_DID_FINISH_LAUNCHING_IDENTIFIER)) {
      console.log("")
      const block = RN_PILGRIM_DID_FINISH_LAUNCHING_IDENTIFIER + RN_PILGRIM_DID_FINISH_LAUNCHING_CODE
      appDelegate = appDelegate.replace(RN_PILGRIM_DID_FINISH_LAUNCHING_IDENTIFIER, block)
    } else {
      throw new Error('Failed to detect didFinishLaunchingWithOptions in AppDelegate.m')
    }
    return appDelegate
  }

const withPilgrimSupportIOS: ConfigPlugin = (config) => {
  console.log("withPilgrimSupportIOS");
    return withAppDelegate(config, (config) => {
      console.log("withAppDelegate");
      console.log(['objc', 'objcpp'].includes(config.modResults.language));
        if (['objc', 'objcpp'].includes(config.modResults.language)) {
            config.modResults.contents = modifyAppDelegate(config.modResults.contents)
        } else {
            WarningAggregator.addWarningIOS('withPilgrimSupportIOSAppDelegate', `Cannot setup Pilgrim SDK, the project AppDelegate is not a supported language: ${config.modResults.language}`)
        }
        return config
    })
}

export const withRnPilgrimIOS: ConfigPlugin = (config) => {
  config = withPilgrimSupportIOS(config);
  return config
}

export default withRnPilgrimIOS(config);

I added these console logs to communicate that when I run expo prebuild --clean, I see “withPilgrimSupportIOS” logged but not “withAppDelegate” which makes me think there is something wrong with my implementation of withAppDelegate.

Any suggestions on how I can fix this?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.