Skip to content
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
8 changes: 8 additions & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Unreleased

### Added

- Added new methods to help users resolve permission and sensor-related issues within the app. With these new methods, the SDK can now automatically request the necessary permissions for positioning without the need to implement repetitive code:
- configureUserHelper(options): Automatically detects and explains configuration problems (such as missing Location or Bluetooth permissions, or disabled sensors), and guides the user through the steps to fix them. Accepts a configuration object to customize the behavior.
- enableUserHelper(): Shortcut to enable the user guidance with default settings
- disableUserHelper(): Shortcut to disable the user guidance with default settings
27 changes: 27 additions & 0 deletions android/src/main/java/com/situm/plugin/PluginHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import es.situm.sdk.v1.SitumEvent;
import es.situm.sdk.location.GeofenceListener;
import es.situm.sdk.navigation.ExternalNavigation;
import es.situm.sdk.userhelper.UserHelperColorScheme;

import static com.situm.plugin.SitumPlugin.EVENT_LOCATION_CHANGED;
import static com.situm.plugin.SitumPlugin.EVENT_LOCATION_ERROR;
Expand Down Expand Up @@ -1013,4 +1014,30 @@ public void onCancellation() {
}
};
}

public void configureUserHelper(ReadableMap map, Callback success, Callback error) {
try {
JSONObject jsonUserHelperOptions = ReactNativeUtils.convertMapToJson(map);
boolean enabled = false;
if (jsonUserHelperOptions.has("enabled")) {
enabled = jsonUserHelperOptions.getBoolean("enabled");
}
if (jsonUserHelperOptions.has("colorScheme")) {
JSONObject jsonColorScheme = jsonUserHelperOptions.getJSONObject("colorScheme");
UserHelperColorScheme colorScheme = SitumMapper.jsonObjectToUserHelperColorScheme(jsonColorScheme);
SitumSdk.userHelperManager().setColorScheme(colorScheme);
}
SitumSdk.userHelperManager().autoManage(enabled);

WritableMap response = Arguments.createMap();
invokeCallback(success, response);

} catch (Exception e) {
Log.d(TAG, "exception: " + e);

WritableMap response = Arguments.createMap();
response.putString("error", e.getMessage());
invokeCallback(error, response);
}
}
}
21 changes: 21 additions & 0 deletions android/src/main/java/com/situm/plugin/SitumMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import es.situm.sdk.v1.SitumEvent;
import es.situm.sdk.location.ForegroundServiceNotificationOptions;
import es.situm.sdk.location.ForegroundServiceNotificationOptions.TapAction;
import es.situm.sdk.userhelper.UserHelperColorScheme;

class SitumMapper {

Expand Down Expand Up @@ -1283,4 +1284,24 @@ public static ReadableArray convertListToReadableArray(List<Object> list) {
}
return response;
}

static UserHelperColorScheme jsonObjectToUserHelperColorScheme(JSONObject args) throws JSONException {
UserHelperColorScheme.Builder builder = new UserHelperColorScheme.Builder();

if (args.has("primaryColor")) {
String primaryColor = args.getString("primaryColor");
if (primaryColor != null) {
builder.setPrimaryColor(primaryColor);
}
}

if (args.has("secondaryColor")) {
String secondaryColor = args.getString("secondaryColor");
if (secondaryColor != null) {
builder.setSecondaryColor(secondaryColor);
}
}

return builder.build();
}
}
4 changes: 2 additions & 2 deletions android/src/main/java/com/situm/plugin/SitumPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ public interface SitumPlugin {

void invalidateCache();

void requestAuthorization();

void getDeviceId(Callback callback);

void onEnterGeofences();

void onExitGeofences();

void configureUserHelper(ReadableMap map, Callback success, Callback error);
}
53 changes: 5 additions & 48 deletions android/src/main/java/com/situm/plugin/SitumPluginImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,54 +290,6 @@ public void getDeviceId(Callback callback) {
callback.invoke(response);
}

@Override
@ReactMethod
public void requestAuthorization() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final PermissionsModule perms = getReactApplicationContext().getNativeModule(PermissionsModule.class);

final Callback onPermissionGranted = new Callback() {
@Override
public void invoke(Object... args) {
String result = (String) args[0];
if (!result.equals("granted")) {
Log.e(TAG, "Location permission was not granted.");
}
}
};

final Callback onPermissionDenied = new Callback() {
@Override
public void invoke(Object... args) {
Log.e(TAG, "Failed to request location permission.");
}
};

Callback onPermissionCheckFailed = new Callback() {
@Override
public void invoke(Object... args) {

Log.e(TAG, "Failed to check location permission.");
}
};

Callback onPermissionChecked = new Callback() {
@Override
public void invoke(Object... args) {
boolean hasPermission = (boolean) args[0];

if (!hasPermission) {
perms.requestPermission(Manifest.permission.ACCESS_FINE_LOCATION,
new PromiseImpl(onPermissionGranted, onPermissionDenied));
}
}
};

perms.checkPermission(Manifest.permission.ACCESS_FINE_LOCATION,
new PromiseImpl(onPermissionChecked, onPermissionCheckFailed));
}
}

@Override
@ReactMethod
public void onEnterGeofences() {
Expand All @@ -351,4 +303,9 @@ public void onExitGeofences() {
getPluginInstance().onExitGeofences(
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class));
}

@ReactMethod
public void configureUserHelper(ReadableMap map, Callback success, Callback error) {
getPluginInstance().configureUserHelper(map, success, error);
}
}
16 changes: 8 additions & 8 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ PODS:
- hermes-engine/Pre-built (0.72.12)
- libevent (2.1.12)
- OpenSSL-Universal (1.1.1100)
- Protobuf (3.29.2)
- Protobuf (3.29.4)
- RCT-Folly (2021.07.22.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -491,18 +491,18 @@ PODS:
- React-jsi (= 0.72.12)
- React-logger (= 0.72.12)
- React-perflogger (= 0.72.12)
- ReactNativeSitumPlugin (3.12.5):
- ReactNativeSitumPlugin (3.14.14):
- RCT-Folly (= 2021.07.22.00)
- React
- React-Core
- SitumSDK (= 3.21.1)
- SitumSDK (= 3.28.1)
- RNPermissions (3.10.1):
- React-Core
- RNScreens (3.32.0):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- React-RCTImage
- SitumSDK (3.21.1):
- SitumSDK (3.28.1):
- Protobuf (~> 3.7)
- SSZipArchive (~> 2.4)
- SocketRocket (0.6.1)
Expand Down Expand Up @@ -710,7 +710,7 @@ SPEC CHECKSUMS:
hermes-engine: e89344b9e9e54351c3c5cac075e0275148fb37ba
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
Protobuf: ba5d83b2201386fec27d484c099cac510ea5c169
Protobuf: 2e6de032ba12b9efb390ae550d1a243a5b19ddfc
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
RCTRequired: b6cea797b684c6d8d82ba0107cef58cbb679afdb
RCTTypeSafety: d2eb5e0e8af9181b24034f5171f9b659994b4678
Expand Down Expand Up @@ -745,15 +745,15 @@ SPEC CHECKSUMS:
React-runtimescheduler: 8aea338c561b2175f47018124c076d89d3808d30
React-utils: 9a24cb88f950d1020ee55bddacbc8c16a611e2dc
ReactCommon: 76843a9bb140596351ac2786257ac9fe60cafabb
ReactNativeSitumPlugin: 389ee181d434a2c57d9598ee99103ab0ba5ea474
ReactNativeSitumPlugin: 354a112a0a92d92dc1c67d55d235fe7e7a268b80
RNPermissions: 4377d1d869b3b32308932b8c11ba47880933d7c6
RNScreens: ad1c105ac9107cf1a613bf80889485458eb20bd7
SitumSDK: dcc8e963d0d80c260786c3f76ea8160714a87d26
SitumSDK: 974f20680e13f115caaa818b48bcc2340b768ffc
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
SSZipArchive: fe6a26b2a54d5a0890f2567b5cc6de5caa600aef
Yoga: 87e59f6d458e5061d2421086c5de994b3f7cd151
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 5bbd3e6d4ded92b8497ea5f670af0806207e3ee6

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@react-navigation/native": "^6.1.1",
"@react-navigation/native-stack": "^6.9.7",
"@situm/react-native": "file:..",
"babel-plugin-module-resolver": "^5.0.2",
"react": "18.2.0",
"react-native": "0.72.12",
"react-native-paper": "^5.10.0",
Expand Down Expand Up @@ -60,4 +61,4 @@
"LocationWhenInUse",
"Motion"
]
}
}
83 changes: 0 additions & 83 deletions example/src/examples/Utils/requestPermission.tsx

This file was deleted.

16 changes: 5 additions & 11 deletions example/src/examples/sdk/Positioning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import SitumPlugin, {
} from '@situm/react-native';
import styles from '../styles/styles';
import {Button, Card, Divider, List} from 'react-native-paper';
import requestPermission from '../Utils/requestPermission';

function PositioningScreen() {
// State variables to store location, status, error, and geofences data
Expand All @@ -23,6 +22,10 @@ function PositioningScreen() {
SitumPlugin.setConfiguration({
useRemoteConfig: false,
});
// Tells the underlying native SDKs to automatically manage permissions
// and sensor related issues.
SitumPlugin.enableUserHelper();

registerCallbacks();

return () => {
Expand All @@ -32,20 +35,11 @@ function PositioningScreen() {
}, []);

const handlePermissionsButton = async () => {
try {
await requestPermission();
} catch (e) {
console.error('Error requesting permissions:', e);
}
// Do nothing
};

// Start positioning using Situm SDK
const startPositioning = async () => {
try {
await requestPermission();
} catch (e) {
console.warn('Situm > example > Error starting positioning:', e);
}

console.log('Starting positioning');
setLocation('');
Expand Down
Loading