Skip to content
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

add addRadarSDKVerify option #367

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ repositories {

dependencies {
api 'com.facebook.react:react-native:+'
api 'io.radar:sdk:3.18.6'
api 'io.radar:sdk:3.18.8-beta.1'
}

10 changes: 10 additions & 0 deletions android/src/main/java/io/radar/react/RNRadarModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,16 @@ public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarVerifie
Radar.getVerifiedLocationToken(trackCallback);
}

@ReactMethod
public void startVerifyServer() {
Radar.startVerifyServer();
}

@ReactMethod
public void stopVerifyServer() {
Radar.stopVerifyServer();
}

@ReactMethod
public void startTrackingEfficient() {
Radar.startTracking(RadarTrackingOptions.EFFICIENT);
Expand Down
14 changes: 14 additions & 0 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,20 @@ export default function App() {
}}
/>

<ExampleButton
title="startVerifyServer"
onPress={() => {
Radar.startVerifyServer();
}}
/>

<ExampleButton
title="stopVerifyServer"
onPress={() => {
Radar.stopVerifyServer();
}}
/>

<ExampleButton
title="version"
onPress={() => {
Expand Down
5 changes: 3 additions & 2 deletions example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.radar.example",
"bundleIdentifier": "com.radar.example"
},
"android": {
"adaptiveIcon": {
Expand All @@ -38,7 +38,8 @@
"androidFraud": true,
"androidBackgroundPermission": true,
"androidFineLocationPermission": true,
"addRadarSDKMotion": true
"addRadarSDKMotion": false,
"addRadarSDKVerify": true
}
],
[
Expand Down
78 changes: 29 additions & 49 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions ios/RNRadar.m
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ - (void)didUpdateToken:(RadarVerifiedLocationToken *)token {
[Radar getVerifiedLocationToken:completionHandler];
}

RCT_EXPORT_METHOD(startVerifyServer) {
[Radar startVerifyServer];
}

RCT_EXPORT_METHOD(stopVerifyServer) {
[Radar stopVerifyServer];
}

RCT_EXPORT_METHOD(startTrackingEfficient) {
[Radar startTrackingWithOptions:RadarTrackingOptions.presetEfficient];
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "React Native module for Radar, the leading geofencing and location tracking platform",
"homepage": "https://radar.com",
"license": "Apache-2.0",
"version": "3.18.5",
"version": "3.19.0-beta.2",
"main": "dist/index.js",
"files": [
"/android",
Expand Down
1 change: 1 addition & 0 deletions plugin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface RadarPluginProps {
androidFineLocationPermission?: boolean;
addRadarSDKMotion?: boolean;
iosNSMotionUsageDescription?: string;
addRadarSDKVerify?: boolean;
}
15 changes: 13 additions & 2 deletions plugin/src/withRadarAndroid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const withRadarAndroid = (
<!-- for React Native -->
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">10.0.2.2</domain>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localhost on Android emulator

</domain-config>

<!-- for SSL pinning -->
Expand All @@ -82,7 +83,8 @@ export const withRadarAndroid = (
if (config.modResults.language === "groovy") {
config.modResults.contents = modifyAppBuildGradle(
config.modResults.contents,
args.androidFraud ?? false
args.androidFraud ?? false,
args.addRadarSDKVerify ?? false
);
} else {
throw new Error(
Expand Down Expand Up @@ -150,9 +152,10 @@ async function setCustomConfigAsync(
return androidManifest;
}

function modifyAppBuildGradle(buildGradle: string, androidFraud: boolean) {
function modifyAppBuildGradle(buildGradle: string, androidFraud: boolean, addRadarSDKVerify: boolean) {
let hasLocationService = false;
let hasPlayIntegrity = false;
let hasNanoHTTPD = false;
if (
buildGradle.includes(
'com.google.android.gms:play-services-location:21.0.1"'
Expand All @@ -165,6 +168,10 @@ function modifyAppBuildGradle(buildGradle: string, androidFraud: boolean) {
hasPlayIntegrity = true;
}

if (buildGradle.includes('org.nanohttpd:nanohttpd:2.3.1"')) {
hasNanoHTTPD = true;
}

const pattern = /^dependencies {/m;

if (!buildGradle.match(pattern)) {
Expand All @@ -184,6 +191,10 @@ function modifyAppBuildGradle(buildGradle: string, androidFraud: boolean) {
replacementString +=
"\n\n" + ' implementation "com.google.android.play:integrity:1.2.0"';
}
if (addRadarSDKVerify && !hasNanoHTTPD) {
replacementString +=
"\n\n" + ' implementation "org.nanohttpd:nanohttpd:2.3.1"';
}

return buildGradle.replace(
pattern,
Expand Down
30 changes: 30 additions & 0 deletions plugin/src/withRadarIOS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ export const withRadarIOS: ConfigPlugin<RadarPluginProps> = (config, args) => {
},
]);
}
if (args.addRadarSDKVerify) {
config = withDangerousMod(config, [
'ios',
async config => {
const filePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');
const contents = await fs.readFile(filePath, 'utf-8');

// Check if the pod declaration already exists
if (contents.indexOf("pod 'RadarSDK/Verify', '3.19.2-beta.9'") === -1) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmeier @KennyHuRadar Similar to addRadarSDKMotion option. Will we need to update the version by hand in both places?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably extract this to a constant in the future. Since we release all the sdks with matching versions (I think, since RadarSDKMotion releases a 3.19 together with a 3.19 main SDK even if there is no change). We can probably just update the version string in the podspec file, and we can read the version from there and use it across the plugin.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that's exactly correct — easiest to maintain the same version across the the main module and all submodules.

// Find the target block
const targetRegex = /target '(\w+)' do/g;
const match = targetRegex.exec(contents);
if (match) {
const targetStartIndex = match.index;
const targetEndIndex = contents.indexOf('end', targetStartIndex) + 3;

// Insert the pod declaration within the target block
const targetBlock = contents.substring(targetStartIndex, targetEndIndex);
const updatedTargetBlock = targetBlock.replace(/(target '(\w+)' do)/, `$1\n pod 'RadarSDK/Verify', '3.19.2-beta.9'\n pod 'CocoaAsyncSocket', :modular_headers => true\n pod 'HTTPParserC', :modular_headers => true`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Telegraph sub-dependencies need modular_headers => true

const newContents = contents.replace(targetBlock, updatedTargetBlock);

// Write the updated contents back to the Podfile
await fs.writeFile(filePath, newContents);
}
}

return config;
},
]);
}

return config;
};
4 changes: 2 additions & 2 deletions react-native-radar.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Pod::Spec.new do |s|
s.summary = package[:description]
s.source = { git: package[:repository][:url] }
s.source_files = "ios/*.{h,m}"
s.platform = :ios, "10.0"
s.platform = :ios, "12.0"

s.dependency "React"
s.dependency "RadarSDK", "~> 3.18.5"
s.dependency "RadarSDK", "~> 3.19.2-beta.9"
end
2 changes: 1 addition & 1 deletion react-native-radar.podspec.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.summary = package[:description]
s.source = { git: package[:repository][:url] }
s.source_files = "ios/*.{h,m}"
s.platform = :ios, "10.0"
s.platform = :ios, "12.0"

s.dependency "React"
s.dependency "RadarSDK", "~> {{ version }}"
Expand Down
2 changes: 2 additions & 0 deletions src/@types/RadarNativeInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export interface RadarNativeInterface {
) => Promise<RadarTrackCallback>;
trackVerified: (options?: RadarTrackVerifiedOptions) => Promise<RadarTrackVerifiedCallback>;
getVerifiedLocationToken: () => Promise<RadarTrackVerifiedCallback>;
startVerifyServer: () => void;
stopVerifyServer: () => void;
startTrackingEfficient: () => void;
startTrackingResponsive: () => void;
startTrackingContinuous: () => void;
Expand Down
8 changes: 8 additions & 0 deletions src/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ const trackVerified = (
const getVerifiedLocationToken = (): Promise<RadarTrackVerifiedCallback> =>
NativeModules.RNRadar.getVerifiedLocationToken();

const startVerifyServer = (): void =>
NativeModules.RNRadar.startVerifyServer();

const stopVerifyServer = (): void =>
NativeModules.RNRadar.stopVerifyServer();

const startTrackingEfficient = (): void =>
NativeModules.RNRadar.startTrackingEfficient();

Expand Down Expand Up @@ -263,6 +269,8 @@ const Radar: RadarNativeInterface = {
trackOnce,
trackVerified,
getVerifiedLocationToken,
startVerifyServer,
stopVerifyServer,
startTrackingEfficient,
startTrackingResponsive,
startTrackingContinuous,
Expand Down
Loading