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

move types out to separate file so it can be shared with react-native… #106

Open
wants to merge 8 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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- run: cd example && npm install
- run: cd example && ionic build
- run: cd example && npx cap sync
- run: cd example && ionic capacitor run ios --target $(ionic capacitor run ios --list | grep -o -m 1 '[A-F0-9]\{8\}-[A-F0-9]\{4\}-[A-F0-9]\{4\}-[A-F0-9]\{4\}-[A-F0-9]\{12\}')
- run: cd example && ionic capacitor run ios --target $(ionic capacitor run ios --list | grep 'iPhone' | grep -o -m 1 '[A-F0-9]\{8\}-[A-F0-9]\{4\}-[A-F0-9]\{4\}-[A-F0-9]\{4\}-[A-F0-9]\{12\}')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sure target is an iPhone, it wasn't working possibly due to it selected apple vision pro as the device.

workflows:
version: 2
android-ios:
Expand Down
23 changes: 20 additions & 3 deletions android/src/main/java/io/radar/capacitor/RadarPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,12 @@ public void onTokenUpdated(@NonNull Context context, @NonNull RadarVerifiedLocat
@PluginMethod()
public void initialize(PluginCall call) {
String publishableKey = call.getString("publishableKey");
Boolean fraud = call.getBoolean("fraud", false);
SharedPreferences.Editor editor = this.getContext().getSharedPreferences("RadarSDK", Context.MODE_PRIVATE).edit();
editor.putString("x_platform_sdk_type", "Capacitor");
editor.putString("x_platform_sdk_version", "3.12.0");
editor.apply();
Radar.initialize(this.getContext(), publishableKey);
Radar.initialize(this.getContext(), publishableKey, null, Radar.RadarLocationServicesProvider.GOOGLE, fraud);
call.resolve();
}

Expand Down Expand Up @@ -328,7 +329,7 @@ public void onComplete(@NotNull Radar.RadarStatus status, @Nullable Location loc
}

@PluginMethod()
public void trackOnce(final PluginCall call) {
public void trackOnce(final PluginCall call) throws JSONException {
Radar.RadarTrackCallback callback = new Radar.RadarTrackCallback() {
@Override
public void onComplete(@NotNull Radar.RadarStatus status, @Nullable Location location, @Nullable RadarEvent[] events, @Nullable RadarUser user) {
Expand All @@ -345,7 +346,23 @@ public void onComplete(@NotNull Radar.RadarStatus status, @Nullable Location loc
}
};

if (call.hasOption("latitude") && call.hasOption("longitude") && call.hasOption("accuracy")) {
if (call.hasOption("location")) {
JSObject locationObj = call.getObject("location");

double latitude = locationObj.getDouble("latitude");
double longitude = locationObj.getDouble("longitude");
if (!locationObj.has("accuracy")) {
call.reject("location accuracy is required");
return;
}
float accuracy = (float)locationObj.getDouble("accuracy");
Location location = new Location("RadarSDK");
location.setLatitude(latitude);
location.setLongitude(longitude);
location.setAccuracy(accuracy);

Radar.trackOnce(location, callback);
} else if (call.hasOption("latitude") && call.hasOption("longitude") && call.hasOption("accuracy")) {
double latitude = call.getDouble("latitude");
double longitude = call.getDouble("longitude");
float accuracy = call.getDouble("accuracy").floatValue();
Expand Down
19 changes: 15 additions & 4 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class App extends React.Component<AppProps, AppState> {
}

componentDidMount() {
Radar.initialize({ publishableKey: 'prj_test_pk_0000000000000000000000000000000000000000' });
Radar.initialize({ publishableKey: 'prj_test_pk_26da2abbdc9c6ffc86afcbc3df0bbde4f8d4e1f8' });
Radar.setLogLevel({level: 'debug'});
Radar.setUserId({ userId: 'capacitor' });
Radar.setDescription({ description: 'capacitor example'});
Expand Down Expand Up @@ -123,6 +123,17 @@ class App extends React.Component<AppProps, AppState> {
}).catch((error) => {
this.logOutput(`trackOnce: error ${JSON.stringify(error)}\n`);
});
Radar.trackOnce({
location: {
latitude: 40,
longitude: -73,
accuracy: 0,
}
}).then((result) => {
this.logOutput(`trackOnce with location: ${JSON.stringify(result)}\n`);
}).catch((error) => {
this.logOutput(`trackOnce with location: error ${JSON.stringify(error)}\n`);
});
Radar.isTracking().then((result) => {
this.logOutput(`isTracking: ${JSON.stringify(result)}\n`);
}).catch((error) => {
Expand Down Expand Up @@ -245,8 +256,8 @@ class App extends React.Component<AppProps, AppState> {

Radar.trackVerified().then((result) => {
this.logOutput(`trackVerified: ${JSON.stringify(result)}\n`);
const { user } = result;
if (user?.fraud?.passed && user?.country?.allowed && user?.state?.allowed) {
const { token } = result;
if (token?.passed) {
// allow access to feature
} else {
// deny access to feature, show error message
Expand Down Expand Up @@ -335,7 +346,7 @@ class App extends React.Component<AppProps, AppState> {
destinationGeofenceTag: "store",
destinationGeofenceExternalId: "123",
mode: "car",
scheduledArrivalAt: scheduledArrivalAt
scheduledArrivalAt: scheduledArrivalAt.toISOString(),
},
trackingOptions: {
"desiredStoppedUpdateInterval": 30,
Expand Down
14 changes: 11 additions & 3 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,17 @@ public class RadarPlugin: CAPPlugin, RadarDelegate, RadarVerifiedDelegate {
}
}

let latitude = call.getDouble("latitude") ?? 0.0
let longitude = call.getDouble("longitude") ?? 0.0
let accuracy = call.getDouble("accuracy") ?? 0.0
var latitude = call.getDouble("latitude") ?? 0.0
var longitude = call.getDouble("longitude") ?? 0.0
var accuracy = call.getDouble("accuracy") ?? 0.0

let locationDict = call.getObject("location") as? [String:Double] ?? nil
if (locationDict != nil) {
latitude = locationDict?["latitude"] ?? 0.0
longitude = locationDict?["longitude"] ?? 0.0
accuracy = locationDict?["accuracy"] ?? 0.0
}

let coordinate = CLLocationCoordinate2DMake(latitude, longitude)
let location = CLLocation(coordinate: coordinate, altitude: -1, horizontalAccuracy: accuracy, verticalAccuracy: -1, timestamp: Date())
var accuracyLevel = RadarTrackingOptions.desiredAccuracy(for:"medium")
Expand Down
Loading