Skip to content

fix: update Swift delegate method to correctly register RNBatch and m… #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions plugin/src/ios/withReactNativeBatchAppDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ export const modifyObjCDelegate = (contents: string): string => {

// MARK : - Swift

const DID_FINISH_LAUNCHING_WITH_OPTIONS_SWIFT_DECLARATION = `@UIApplicationMain
public class AppDelegate: ExpoAppDelegate {
public override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {`;
const DID_FINISH_LAUNCHING_WITH_OPTIONS_SWIFT_DECLARATION = 'return super.application(application, didFinishLaunchingWithOptions: launchOptions)';
const IMPORT_SWIFT_BATCH = '\n\nimport RNBatchPush\n';
const REGISTER_SWIFT_BATCH = '\n RNBatch.start()\n';

Expand All @@ -31,11 +26,10 @@ export const modifySwiftDelegate = (contents: string): string => {
export const modifyDelegate = (contents: string, importBatch: string, declaration: string, register: string): string => {
contents = contents.replace('\n', importBatch);

const [beforeDeclaration, afterDeclaration] = contents.split(declaration);
if (contents.includes(declaration) && !contents.includes(register)) {
contents = contents.replace(declaration, `${register} ${declaration}`);
}

const newAfterDeclaration = declaration.concat(register).concat(afterDeclaration);

contents = beforeDeclaration.concat(newAfterDeclaration);
return contents;
};

Expand Down