Skip to content

Commit a6a1fcc

Browse files
author
杨毅
committed
fix: iOS native code support new arch
1 parent 5a9f187 commit a6a1fcc

4 files changed

Lines changed: 30 additions & 22 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@
168168
"jsSrcsDir": "src",
169169
"android": {
170170
"javaPackageName": "com.detectfrida"
171+
},
172+
"ios": {
173+
"modulesProvider": {
174+
"DetectFrida": "DetectFrida"
175+
}
171176
}
172177
}
173178
}

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)