Skip to content

Commit

Permalink
Upgrade to 3.5.9 (#73)
Browse files Browse the repository at this point in the history
* add support for SDK 3.5.9

* make trackingOptions optional

* fix compile error

* add guard to fix complile errors

* support both old and new param styles

* add a migration for the new trackingOption param

* updated migration copy

* example app testing changes

* fix attr name
  • Loading branch information
tjulien committed Dec 6, 2022
1 parent a7df467 commit e2c1705
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CapacitorRadar.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '12.0'
s.dependency 'Capacitor'
s.dependency 'RadarSDK', '~> 3.4.4'
s.dependency 'RadarSDK', '~> 3.5.9'
s.static_framework = true
end
49 changes: 49 additions & 0 deletions MIGRATION.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Migration guides

## 3.5.0 to 3.5.2
- the `startTrip` function now accepts `tripOptions` and `trackingOptions` in the `options` param:
`startTrip( { options: { tripOptions, trackingOptions } } )`. The SDK will now automatically `startTracking` using `trackingOptions` when a trip is created.

```javascript
// 3.5.2 - new param format
Radar.startTrip({
options: {
tripOptions: {
externalId: "1600",
destinationGeofenceTag: "store",
destinationGeofenceExternalId: "12345"
},
trackingOptions: {
"desiredStoppedUpdateInterval": 30,
"fastestStoppedUpdateInterval": 30,
"desiredMovingUpdateInterval": 30,
"fastestMovingUpdateInterval": 30,
"desiredSyncInterval": 20,
"desiredAccuracy": "high",
"stopDuration": 0,
"stopDistance": 0,
"replay": "none",
"sync": "all",
"showBlueBar": true,
"useStoppedGeofence": false,
"stoppedGeofenceRadius": 0,
"useMovingGeofence": false,
"movingGeofenceRadius": 0,
"syncGeofences": false,
"syncGeofencesLimit": 0,
"beacons": false,
"foregroundServiceEnabled": false
}
}
})
```

```javascript
// 3.5.0 - deprecated param format
Radar.startTrip({
options: {
externalId: "1600",
destinationGeofenceTag: "store",
destinationGeofenceExternalId: "12345"
}
})
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'io.radar:sdk:3.5.6'
implementation 'io.radar:sdk:3.5.9'
}
16 changes: 14 additions & 2 deletions android/src/main/java/io/radar/capacitor/RadarPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,20 @@ public void startTrip(PluginCall call) {
call.reject("options is required");
return;
}
RadarTripOptions options = RadarTripOptions.fromJson(optionsJson);
Radar.startTrip(options, new Radar.RadarTripCallback() {
// new format is { tripOptions, trackingOptions }
JSONObject tripOptionsJson = optionsJson.optJSONObject("tripOptions");
if (tripOptionsJson == null) {
// legacy format
tripOptionsJson = optionsJson;
}
RadarTripOptions options = RadarTripOptions.fromJson(tripOptionsJson);

RadarTrackingOptions trackingOptions = null;
JSONObject trackingOptionsJson = optionsJson.optJSONObject("trackingOptions");
if (trackingOptionsJson != null) {
trackingOptions = RadarTrackingOptions.fromJson(trackingOptionsJson);
}
Radar.startTrip(options, trackingOptions, new Radar.RadarTripCallback() {
@Override
public void onComplete(@NonNull Radar.RadarStatus status,
@Nullable RadarTrip trip,
Expand Down
3 changes: 1 addition & 2 deletions example/package-lock.json

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

79 changes: 73 additions & 6 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class App extends React.Component {

Radar.requestLocationPermissions({ background: false });

Radar.trackOnce().then((result) => {
/*Radar.trackOnce().then((result) => {
alert(JSON.stringify(result));
});
});*/

// var stopTrackingTime = new Date()
// stopTrackingTime.setMinutes(stopTrackingTime.getMinutes() + 1)
Expand All @@ -68,21 +68,88 @@ class App extends React.Component {

var scheduledArrivalAt = new Date()
scheduledArrivalAt.setMinutes(scheduledArrivalAt.getMinutes() + 9)
Radar.startTrip({
/*Radar.startTrip({
options: {
externalId: 1564,
destinationGeofenceTag: "Home",
destinationGeofenceExternalId: "119",
externalId: "1601",
destinationGeofenceTag: "foo",
destinationGeofenceExternalId: "bamly",
scheduledArrivalAt: scheduledArrivalAt
}
}).then((result) => {
alert(`trip ${JSON.stringify(result.trip)}`)
Radar.startTrackingResponsive()
if (result.status == "SUCCESS") {
Radar.startTrackingResponsive()
} else {
alert(`failed to start trip ${JSON.stringify(result)}`);
}
}).catch((error) => {
alert(`error ${JSON.stringify(error)}`);
});*/

/*Radar.startTrip({
options: {
tripOptions: {
externalId: "1597",
destinationGeofenceTag: "foo",
destinationGeofenceExternalId: "bamly",
scheduledArrivalAt: scheduledArrivalAt
}
}
}).then((result) => {
alert(`trip ${JSON.stringify(result.trip)}`)
if (result.status == "SUCCESS") {
Radar.startTrackingResponsive()
} else {
alert(`failed to start trip ${JSON.stringify(result)}`);
}
}).catch((error) => {
alert(`error ${JSON.stringify(error)}`);
});*/

Radar.startTrip({
options: {
tripOptions: {
externalId: "1600",
destinationGeofenceTag: "foo",
destinationGeofenceExternalId: "bamly",
scheduledArrivalAt: scheduledArrivalAt
},
trackingOptions: {
"desiredStoppedUpdateInterval": 30,
"fastestStoppedUpdateInterval": 30,
"desiredMovingUpdateInterval": 30,
"fastestMovingUpdateInterval": 30,
"desiredSyncInterval": 20,
"desiredAccuracy": "HIGH",
"stopDuration": 0,
"stopDistance": 0,
"replay": "none",
"sync": "all",
"showBlueBar": true,
"useStoppedGeofence": false,
"stoppedGeofenceRadius": 0,
"useMovingGeofence": false,
"movingGeofenceRadius": 0,
"syncGeofences": false,
"syncGeofencesLimit": 0,
"beacons": false,
"foregroundServiceEnabled": false
}
}
}).then((result) => {
alert(`trip ${JSON.stringify(result.trip)}`)

if (result.status == "SUCCESS") {

} else {
alert(`failed to start trip ${JSON.stringify(result)}`);
}
}).catch((error) => {
alert(`error ${JSON.stringify(error)}`);
});

/*
Expand Down
28 changes: 24 additions & 4 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ public class RadarPlugin: CAPPlugin, RadarDelegate {
@objc func startTrackingCustom(_ call: CAPPluginCall) {
DispatchQueue.main.async {
let trackingOptionsDict = call.getObject("options") ?? [:]
let trackingOptions = RadarTrackingOptions(from: trackingOptionsDict)
guard let trackingOptions = RadarTrackingOptions(from: trackingOptionsDict) else {
call.reject("options is required")

return
}
Radar.startTracking(trackingOptions: trackingOptions)
call.resolve()
}
Expand Down Expand Up @@ -270,8 +274,20 @@ public class RadarPlugin: CAPPlugin, RadarDelegate {
@objc func startTrip(_ call: CAPPluginCall) {
DispatchQueue.main.async {
let optionsDict = call.getObject("options") ?? [:]
let options = RadarTripOptions(from: optionsDict)
Radar.startTrip(options: options) { (status: RadarStatus, trip: RadarTrip?, events: [RadarEvent]?) in
// { tripOptions, trackingOptions } is the new req format.
// fallback to reading trip options from the top level options.
let tripOptionsDict = optionsDict["tripOptions"] as? [String:Any] ?? optionsDict
guard let options = RadarTripOptions(from: tripOptionsDict) else {
call.reject("tripOptions is required")

return
}
let trackingOptionsDict = optionsDict["trackingOptions"] as? [String:Any]
var trackingOptions: RadarTrackingOptions?
if (trackingOptionsDict != nil) {
trackingOptions = RadarTrackingOptions(from: trackingOptionsDict!)
}
Radar.startTrip(options: options, trackingOptions: trackingOptions) { (status: RadarStatus, trip: RadarTrip?, events: [RadarEvent]?) in
call.resolve([
"status": Radar.stringForStatus(status),
"trip": trip?.dictionaryValue() ?? {},
Expand All @@ -284,7 +300,11 @@ public class RadarPlugin: CAPPlugin, RadarDelegate {
@objc func updateTrip(_ call: CAPPluginCall) {
DispatchQueue.main.async {
let optionsDict = call.getObject("options") ?? [:]
let options = RadarTripOptions(from: optionsDict)
guard let options = RadarTripOptions(from: optionsDict) else {
call.reject("options is required")

return
}
let statusStr = call.getString("status")
var status = RadarTripStatus.unknown
if statusStr == "STARTED" || statusStr == "started" {
Expand Down
4 changes: 2 additions & 2 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ platform :ios, '12.0'
target 'Plugin' do
use_frameworks!
pod 'Capacitor', :path => '../node_modules/@capacitor/ios'
pod 'RadarSDK', '~> 3.4.4'
pod 'RadarSDK', '~> 3.5.9'
end

target 'PluginTests' do
use_frameworks!
pod 'Capacitor', :path => '../node_modules/@capacitor/ios'
pod 'RadarSDK', '~> 3.4.4'
pod 'RadarSDK', '~> 3.5.9'
end
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
@@ -1,6 +1,6 @@
{
"name": "capacitor-radar",
"version": "3.5.1",
"version": "3.5.2",
"description": "Capacitor plugin for Radar, the leading geofencing and location tracking platform",
"main": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
Expand Down

0 comments on commit e2c1705

Please sign in to comment.