Skip to content

Commit d9b2d03

Browse files
authored
Merge pull request #12 from JosephPoplar/fix-ios-new-arch
fix: iOS new arch support
2 parents 03216a3 + a6a1fcc commit d9b2d03

5 files changed

Lines changed: 30 additions & 28 deletions

File tree

ios/DetectFrida.mm

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#import "JailBrokenHelper.h"
33

44
@implementation DetectFrida
5+
6+
57
RCT_EXPORT_MODULE()
68

79
// Example method
@@ -47,6 +49,18 @@ - (BOOL)isJailBroken {
4749
RCT_REMAP_METHOD(isJailBroken,
4850
isJailBrokenWithResolver:(RCTPromiseResolveBlock)resolve
4951
rejecter:(RCTPromiseRejectBlock)reject) {
52+
[self isJailBroken: resolve reject:reject];
53+
}
54+
55+
RCT_EXPORT_METHOD(closeAppAfterDelay:(double)delay) {
56+
[self closeApp:delay];
57+
}
58+
59+
- (void)detectRoot:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
60+
reject(@"-1", @"This function is only for Android", nil);
61+
}
62+
63+
- (void)isJailBroken:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
5064
@try {
5165
BOOL isJailBroken = [self isJailBroken];
5266
resolve(@{@"isRooted": @(isJailBroken)});
@@ -57,10 +71,11 @@ - (BOOL)isJailBroken {
5771
}
5872
}
5973

60-
RCT_EXPORT_METHOD(closeAppAfterDelay:(double)delay) {
61-
[self closeApp:delay];
62-
}
63-
74+
#ifdef RCT_NEW_ARCH_ENABLED
6475

76+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
77+
return std::make_shared<facebook::react::NativeDetectFridaSpecJSI>(params);
78+
}
6579

80+
#endif
6681
@end

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@
166166
"name": "RNDetectFridaSpec",
167167
"type": "modules",
168168
"jsSrcsDir": "src",
169-
"outputDir": {
170-
"ios": "ios/generated",
171-
"android": "android/generated"
172-
},
173-
"includesGeneratedCode": true,
174169
"android": {
175170
"javaPackageName": "com.detectfrida"
171+
},
172+
"ios": {
173+
"modulesProvider": {
174+
"DetectFrida": "DetectFrida"
175+
}
176176
}
177177
}
178178
}

react-native-detect-frida.podspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Pod::Spec.new do |s|
1515
s.source = { :git => "https://github.com/imanshul/react-native-detect-frida.git", :tag => "#{s.version}" }
1616

1717
s.source_files = "ios/**/*.{h,m,mm,cpp}"
18-
s.private_header_files = "ios/generated/**/*.h"
1918

2019
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
2120
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.

src/NativeDetectFrida.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TurboModule } from 'react-native';
1+
import { type TurboModule } from 'react-native';
22
import { TurboModuleRegistry } from 'react-native';
33

44
export interface Spec extends TurboModule {
@@ -21,4 +21,4 @@ export interface Spec extends TurboModule {
2121
closeAppAfterDelay?(delay: number): void;
2222
}
2323

24-
export default TurboModuleRegistry.getEnforcing<Spec>('DetectFrida');
24+
export default TurboModuleRegistry.get<Spec>('DetectFrida');

src/index.tsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
import { NativeModules, Platform } from 'react-native';
22
import type { RootCheckResult } from './ValueTypes';
3+
import NativeDetectFrida from './NativeDetectFrida';
34

4-
const LINKING_ERROR =
5-
`The package 'react-native-detect-frida' doesn't seem to be linked. Make sure: \n\n` +
6-
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
7-
'- You rebuilt the app after installing the package\n' +
8-
'- You are not using Expo Go\n';
9-
10-
const DetectFrida = NativeModules.DetectFrida
11-
? NativeModules.DetectFrida
12-
: new Proxy(
13-
{},
14-
{
15-
get() {
16-
throw new Error(LINKING_ERROR);
17-
},
18-
}
19-
);
5+
const DetectFrida = NativeDetectFrida
6+
? NativeDetectFrida
7+
: NativeModules.DetectFrida;
208

219
const isAndroid = () => {
2210
return Platform.OS === 'android';

0 commit comments

Comments
 (0)