Skip to content

Commit

Permalink
Merge pull request #80 from radarlabs/liammeier/mob-103-bump-capacito…
Browse files Browse the repository at this point in the history
…r-to-most-recent-native

Upgrade Capacitor to Native SDKs 3.7
  • Loading branch information
lmeier committed Apr 6, 2023
2 parents 487bcca + 8c32c1d commit 33405c0
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 99 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.5.9'
s.dependency 'RadarSDK', '~> 3.7.4'
s.static_framework = true
end
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.9'
implementation 'io.radar:sdk:3.8.0'
}
96 changes: 68 additions & 28 deletions android/src/main/java/io/radar/capacitor/RadarPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.radar.sdk.RadarTrackingOptions.RadarTrackingOptionsForegroundService;
import io.radar.sdk.RadarTripOptions;
import io.radar.sdk.model.RadarAddress;
import io.radar.sdk.Radar.RadarAddressVerificationStatus;
import io.radar.sdk.model.RadarContext;
import io.radar.sdk.model.RadarEvent;
import io.radar.sdk.model.RadarGeofence;
Expand Down Expand Up @@ -226,13 +227,6 @@ public void setAnonymousTrackingEnabled(PluginCall call) {
call.resolve();
}

@PluginMethod()
public void setAdIdEnabled(PluginCall call) {
boolean enabled = call.getBoolean("enabled");
Radar.setAdIdEnabled(enabled);
call.resolve();
}

@PluginMethod()
public void getLocationPermissionsStatus(PluginCall call) {
boolean foreground = hasPermission(Manifest.permission.ACCESS_FINE_LOCATION);
Expand Down Expand Up @@ -754,8 +748,9 @@ public void autocomplete(final PluginCall call) throws JSONException {
int limit = call.getInt("limit", 10);
String country = call.getString("country");
String[] layers = RadarPlugin.stringArrayForJSArray(call.getArray("layers"));
boolean expandUnits = call.getBoolean("expandUnits", false);

Radar.autocomplete(query, near, layers, limit, country, new Radar.RadarGeocodeCallback() {
Radar.autocomplete(query, near, layers, limit, country, expandUnits, new Radar.RadarGeocodeCallback() {
@Override
public void onComplete(@NotNull Radar.RadarStatus status, @Nullable RadarAddress[] addresses) {
if (status == Radar.RadarStatus.SUCCESS && addresses != null) {
Expand All @@ -770,6 +765,32 @@ public void onComplete(@NotNull Radar.RadarStatus status, @Nullable RadarAddress
});
}

@PluginMethod()
public void validateAddress(final PluginCall call) throws JSONException {
if (!call.hasOption("address")) {
call.reject("address is required");

return;
}
RadarAddress address = RadarAddress.fromJson(call.getObject("address"));


Radar.validateAddress(address, new Radar.RadarValidateAddressCallback() {
@Override
public void onComplete(@NotNull Radar.RadarStatus status, @Nullable RadarAddress address, @Nullable RadarAddressVerificationStatus verificationStatus) {
if (status == Radar.RadarStatus.SUCCESS && address != null) {
JSObject ret = new JSObject();
ret.put("status", status.toString());
ret.put("address", RadarPlugin.jsObjectForJSONObject(address.toJson()));
ret.put("verificationStatus", Radar.stringForVerificationStatus(verificationStatus));
call.resolve(ret);
} else {
call.reject(status.toString());
}
}
});
}

@PluginMethod()
public void geocode(final PluginCall call) throws JSONException {
if (!call.hasOption("query")) {
Expand Down Expand Up @@ -912,32 +933,51 @@ public void onComplete(@NotNull Radar.RadarStatus status, @Nullable RadarRoutes
}

@PluginMethod()
public void sendEvent(final PluginCall call) throws JSONException {
String customType = call.getString("customType");
public void logConversion(final PluginCall call) throws JSONException {
if (!call.hasOption("name")) {
call.reject("name is required");

return;
}

String name = call.getString("name");
double revenue = call.getDouble("revenue");
JSObject metadataObj = call.getObject("metadata");
JSONObject metadataJson = RadarPlugin.jsonObjectForJSObject(metadataObj);

Radar.sendEvent(customType, metadataJson, new Radar.RadarSendEventCallback() {
@Override
public void onComplete(@NonNull Radar.RadarStatus status, @Nullable Location location, @Nullable RadarEvent[] events, @Nullable RadarUser user) {
if (status == Radar.RadarStatus.SUCCESS) {
JSObject ret = new JSObject();
ret.put("status", status.toString());
if (location != null) {
ret.put("location", RadarPlugin.jsObjectForJSONObject(Radar.jsonForLocation(location)));
}
if (events != null) {
ret.put("events", RadarPlugin.jsArrayForJSONArray(RadarEvent.toJson(events)));
if (revenue > 0) {
Radar.logConversion(name, revenue, metadataJson, new Radar.RadarLogConversionCallback() {
@Override
public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarEvent event) {
if (status == Radar.RadarStatus.SUCCESS) {
JSObject ret = new JSObject();
ret.put("status", status.toString());
if (event != null) {
ret.put("event", event.toJson());
}
call.resolve(ret);
} else {
call.reject(status.toString());
}
if (user != null) {
ret.put("user", RadarPlugin.jsObjectForJSONObject(user.toJson()));
}
});
} else {
Radar.logConversion(name, metadataJson, new Radar.RadarLogConversionCallback() {
@Override
public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarEvent event) {
if (status == Radar.RadarStatus.SUCCESS) {
JSObject ret = new JSObject();
ret.put("status", status.toString());
if (event != null) {
ret.put("event", event.toJson());
}
call.resolve(ret);
} else {
call.reject(status.toString());
}
call.resolve(ret);
} else {
call.reject(status.toString());
}
}
});
});
}
}

@PluginMethod
Expand Down
6 changes: 3 additions & 3 deletions example/package-lock.json

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

31 changes: 24 additions & 7 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ class App extends React.Component<AppProps, AppState> {
foo: 'bar',
}});
Radar.setAnonymousTrackingEnabled({ enabled: true});
Radar.setAdIdEnabled({ enabled: true });


Radar.getLocationPermissionsStatus().then((result) => {
this.logOutput(JSON.stringify(result));
});
Expand Down Expand Up @@ -114,13 +113,22 @@ class App extends React.Component<AppProps, AppState> {
}).catch((error) => {
this.logOutput(`getTrackingOptions: error ${JSON.stringify(error)}\n`);
});
Radar.sendEvent({
customType: "in_app_purchase",
metadata: {"price": "150USD"}
Radar.logConversion({
name: "viewed_product",
metadata: {"sku": "tshirt"}
}).then((result) => {
this.logOutput(`sendEvent: ${JSON.stringify(result)}\n`);
this.logOutput(`logConversion: ${JSON.stringify(result)}\n`);
}).catch((error) => {
this.logOutput(`sendEvent: error ${JSON.stringify(error)}\n`);
this.logOutput(`logConversion: error ${JSON.stringify(error)}\n`);
});
Radar.logConversion({
name: "in_app_purchase",
revenue: 150,
metadata: {"sku": "tshirt"}
}).then((result) => {
this.logOutput(`logConversion: ${JSON.stringify(result)}\n`);
}).catch((error) => {
this.logOutput(`logConversion: error ${JSON.stringify(error)}\n`);
});
Radar.getTripOptions().then((result) => {
this.logOutput(`getTripOptions: ${JSON.stringify(result)}\n`);
Expand Down Expand Up @@ -169,6 +177,15 @@ class App extends React.Component<AppProps, AppState> {
country: 'US'
}).then((result) => {
this.logOutput(`autocomplete: ${JSON.stringify(result)}\n`);
const address = (result && result.addresses && result.addresses[0]);

if (address) {
Radar.validateAddress({address: address}).then((result) => {
this.logOutput(`validateAddress: ${JSON.stringify(result)}\n`);
}).catch((error) => {
this.logOutput(`validateAddress: error ${JSON.stringify(error)}\n`);
});
}
}).catch((error) => {
this.logOutput(`autocomplete: error ${JSON.stringify(error)}\n`);
});
Expand Down
4 changes: 2 additions & 2 deletions ios/Plugin/Plugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
CAP_PLUGIN_METHOD(setMetadata, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getMetadata, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(setAnonymousTrackingEnabled, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(setAdIdEnabled, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getLocationPermissionsStatus, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(requestLocationPermissions, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getLocation, CAPPluginReturnPromise);
Expand All @@ -36,10 +35,11 @@
CAP_PLUGIN_METHOD(searchPlaces, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(searchGeofences, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(autocomplete, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(validateAddress, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(geocode, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(reverseGeocode, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(ipGeocode, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getDistance, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(sendEvent, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(logConversion, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getMatrix, CAPPluginReturnPromise);
)
62 changes: 38 additions & 24 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,6 @@ public class RadarPlugin: CAPPlugin, RadarDelegate {
}
}

@objc func setAdIdEnabled(_ call: CAPPluginCall) {
DispatchQueue.main.async {
guard let enabled = call.getBool("enabled") else {
call.reject("enabled is required")

return
};
Radar.setAdIdEnabled(enabled)
call.resolve()
}
}


@objc func getLocationPermissionsStatus(_ call: CAPPluginCall) {
DispatchQueue.main.async {
let authorizationStatus = CLLocationManager.authorizationStatus()
Expand Down Expand Up @@ -623,8 +610,9 @@ public class RadarPlugin: CAPPlugin, RadarDelegate {
let limit = Int32(call.getInt("limit") ?? 10)
let country = call.getString("country")
let layers = call.getArray("layers", String.self)
let expandUnits = call.getBool("expandUnits") ?? false

Radar.autocomplete(query: query, near: near, layers: layers, limit: limit, country: country) { (status: RadarStatus, addresses: [RadarAddress]?) in
Radar.autocomplete(query: query, near: near, layers: layers, limit: limit, country: country, expandUnits: expandUnits) { (status: RadarStatus, addresses: [RadarAddress]?) in
if status == .success && addresses != nil {
call.resolve([
"status": Radar.stringForStatus(status),
Expand All @@ -637,6 +625,29 @@ public class RadarPlugin: CAPPlugin, RadarDelegate {
}
}

@objc func validateAddress(_ call: CAPPluginCall) {
DispatchQueue.main.async {
guard let address = RadarAddress.init(object: call.getObject("address")) else {
call.reject("address is required")

return
}

Radar.validateAddress(address: address) { (status: RadarStatus, address: RadarAddress?, verificationStatus: RadarAddressVerificationStatus) in
if status == .success && address != nil {

call.resolve([
"status": Radar.stringForStatus(status),
"address": address?.dictionaryValue() ?? [:],
"verificationStatus": Radar.stringForVerificationStatus(verificationStatus)
])
} else {
call.reject(Radar.stringForStatus(status))
}
}
}
}

@objc func geocode(_ call: CAPPluginCall) {
DispatchQueue.main.async {
guard let query = call.getString("query") else {
Expand Down Expand Up @@ -757,29 +768,32 @@ public class RadarPlugin: CAPPlugin, RadarDelegate {
}
}

@objc func sendEvent(_ call: CAPPluginCall) {
@objc func logConversion(_ call: CAPPluginCall) {
DispatchQueue.main.async {
guard let customType = call.getString("customType") else {
call.reject("customType is required")
guard let name = call.getString("name") else {
call.reject("name is required")

return
}
// get revenue and make sure it's a nsnumber
let revenue = call.getString("revenue") != nil ? NSNumber(value: Double(call.getString("revenue")!)!) : nil
let metadata = call.getObject("metadata")
let completionHandler: RadarSendEventCompletionHandler = { (status: RadarStatus, location: CLLocation?, events: [RadarEvent]?, user: RadarUser?) in
if status == .success && location != nil && events != nil && user != nil {
let completionHandler: RadarLogConversionCompletionHandler = { (status: RadarStatus, event: RadarEvent? ) in
if status == .success {
call.resolve([
"status": Radar.stringForStatus(status),
"location": Radar.dictionaryForLocation(location!),
"events": RadarEvent.array(for: events!) ?? [],
"user": user!.dictionaryValue()
"event": event?.dictionaryValue() ?? [:]
])
} else {
call.reject(Radar.stringForStatus(status))
}
}
if revenue != nil {
Radar.logConversion(name: name, revenue: revenue!, metadata: metadata, completionHandler: completionHandler)
} else {
Radar.logConversion(name: name, metadata: metadata, completionHandler: completionHandler)
}
Radar.sendEvent(customType: customType, metadata: metadata, completionHandler: completionHandler)
}

}

@objc func getMatrix(_ call: CAPPluginCall) {
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.5.9'
pod 'RadarSDK', '~> 3.7.4'
end

target 'PluginTests' do
use_frameworks!
pod 'Capacitor', :path => '../node_modules/@capacitor/ios'
pod 'RadarSDK', '~> 3.5.9'
pod 'RadarSDK', '~> 3.7.4'
end
Loading

0 comments on commit 33405c0

Please sign in to comment.