Skip to content

Release 10.1.0 #18

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

Merged
merged 7 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
build_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
10.1.0
----

**Plugin**
- Added Swift/Objective-C compatibility. You can now directly import module `RNBatchPush` into your swift files.

**Expo**
- Added support for Expo SDK 53. Since, as of writing, it is still under preview version, this may not works in future versions.

**Core**
- Fixed an issue where opting the SDK after been opted-out would unexpectedly reset default configurations, such as Do Not Disturb setting.


10.0.1
----

**Plugin**
- Fixed a build issue related to Codegen.
- Batch now publish TypeScript source files since Codegen does not support DTS files for Turbo Module Specifications.


10.0.0
----

Expand Down
1 change: 1 addition & 0 deletions RNBatchPush.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ Pod::Spec.new do |s|
s.dependency "React"
s.dependency 'Batch', '~> 2.1.0'

s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
end
2 changes: 1 addition & 1 deletion ios/RNBatch.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import <React/RCTEventEmitter.h>
#import <Batch/Batch.h>

#define PluginVersion "ReactNative/10.0.1"
#define PluginVersion "ReactNative/10.1.0"

#ifdef RCT_NEW_ARCH_ENABLED
#import <RNBatchSpec/RNBatchSpec.h>
Expand Down
17 changes: 13 additions & 4 deletions ios/RNBatch.mm
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,19 @@ - (NSDictionary*)getConstants {
RCT_EXPORT_METHOD(optIn:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
{
[BatchSDK optIn];
dispatch_async(dispatch_get_main_queue(), ^{
[RNBatch start];
});
if (BatchSDK.isOptedOut) {
// Opt-in SDK
[BatchSDK optIn];

// Get API key and restart sdk
NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
NSString *batchAPIKey = [info objectForKey:@"BatchAPIKey"];
dispatch_async(dispatch_get_main_queue(), ^{
[BatchSDK startWithAPIKey:batchAPIKey];
});
} else {
NSLog(@"RNBatch: Batch SDK is already opted-in");
}
resolve([NSNull null]);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@batch.com/react-native-plugin",
"version": "10.0.1",
"version": "10.1.0",
"description": "Batch.com React-Native Plugin",
"homepage": "https://github.com/BatchLabs/Batch-React-Native-Plugin",
"main": "dist/Batch.js",
Expand Down
9 changes: 9 additions & 0 deletions plugin/src/__tests__/withReactNativeBatchAppDelegate.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { appDelegateExpectedFixture, appDelegateFixture } from '../fixtures/appDelegate';
import { swift_appDelegateExpectedFixture, swift_appDelegateFixture } from '../fixtures/swift_appDelegate';
import { modifyAppDelegate } from '../ios/withReactNativeBatchAppDelegate';

describe(modifyAppDelegate, () => {
Expand All @@ -8,3 +9,11 @@ describe(modifyAppDelegate, () => {
expect(result).toEqual(appDelegateExpectedFixture);
});
});

describe(modifyAppDelegate, () => {
it('should modify the swift_AppDelegate', () => {
const result = modifyAppDelegate(swift_appDelegateFixture);

expect(result).toEqual(swift_appDelegateExpectedFixture);
});
});
91 changes: 91 additions & 0 deletions plugin/src/fixtures/swift_appDelegate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
export const swift_appDelegateFixture = `import React
import Expo

@UIApplicationMain
public class AppDelegate: ExpoAppDelegate {
public override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
self.moduleName = "main"
self.initialProps = [:]

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

public override func bundleURL() -> URL? {
#if DEBUG
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: ".expo/.virtual-metro-entry")
#else
return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
#endif
}

// Linking API
public override func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
return super.application(app, open: url, options: options) || RCTLinkingManager.application(app, open: url, options: options)
}

// Universal Links
public override func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
let result = RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler)
return super.application(application, continue: userActivity, restorationHandler: restorationHandler) || result
}
}
`;

export const swift_appDelegateExpectedFixture = `import React

import RNBatchPush
import Expo

@UIApplicationMain
public class AppDelegate: ExpoAppDelegate {
public override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
RNBatch.start()

self.moduleName = "main"
self.initialProps = [:]

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

public override func bundleURL() -> URL? {
#if DEBUG
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: ".expo/.virtual-metro-entry")
#else
return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
#endif
}

// Linking API
public override func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
return super.application(app, open: url, options: options) || RCTLinkingManager.application(app, open: url, options: options)
}

// Universal Links
public override func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
let result = RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler)
return super.application(application, continue: userActivity, restorationHandler: restorationHandler) || result
}
}
`;
44 changes: 37 additions & 7 deletions plugin/src/ios/withReactNativeBatchAppDelegate.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
import { ConfigPlugin, withAppDelegate } from '@expo/config-plugins';

const DID_FINISH_LAUNCHING_WITH_OPTIONS_DECLARATION =
// MARK : - Objectif-c

const DID_FINISH_LAUNCHING_WITH_OPTIONS_OBJC_DECLARATION =
'- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions\n{';
const IMPORT_OBJC_BATCH = '\n\n#import <RNBatchPush/RNBatch.h>\n';
const REGISTER_OBJC_BATCH = '\n [RNBatch start];\n';

export const modifyObjCDelegate = (contents: string): string => {
return modifyDelegate(contents, IMPORT_OBJC_BATCH, DID_FINISH_LAUNCHING_WITH_OPTIONS_OBJC_DECLARATION, REGISTER_OBJC_BATCH);
};

const IMPORT_BATCH = '\n\n#import <RNBatchPush/RNBatch.h>\n';
const REGISTER_BATCH = '\n [RNBatch start];\n';
// 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 IMPORT_SWIFT_BATCH = '\n\nimport RNBatchPush\n';
const REGISTER_SWIFT_BATCH = '\n RNBatch.start()\n';

export const modifySwiftDelegate = (contents: string): string => {
return modifyDelegate(contents, IMPORT_SWIFT_BATCH, DID_FINISH_LAUNCHING_WITH_OPTIONS_SWIFT_DECLARATION, REGISTER_SWIFT_BATCH);
};

export const modifyAppDelegate = (contents: string) => {
contents = contents.replace('\n', IMPORT_BATCH);
// MARK : - Common

const [beforeDeclaration, afterDeclaration] = contents.split(DID_FINISH_LAUNCHING_WITH_OPTIONS_DECLARATION);
export const modifyDelegate = (contents: string, importBatch: string, declaration: string, register: string): string => {
contents = contents.replace('\n', importBatch);

const newAfterDeclaration = DID_FINISH_LAUNCHING_WITH_OPTIONS_DECLARATION.concat(REGISTER_BATCH).concat(afterDeclaration);
const [beforeDeclaration, afterDeclaration] = contents.split(declaration);

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

contents = beforeDeclaration.concat(newAfterDeclaration);
return contents;
Expand All @@ -23,3 +45,11 @@ export const withReactNativeBatchAppDelegate: ConfigPlugin<object | void> = conf
return config;
});
};

export const modifyAppDelegate = (content: string): string => {
return isObjCDelegate(content) ? modifyObjCDelegate(content) : modifySwiftDelegate(content);
};

const isObjCDelegate = (content: string): boolean => {
return content.includes('@interface AppDelegate () <RCTBridgeDelegate>');
};