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

Feature/pro 2694 sdk wyf #228

Merged
merged 3 commits into from
Mar 31, 2023
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
## [Unreleased]

### Changed
* Updated iOS SDK to version 2.59.0.
* Refactored `startPositioning()` and `stopPositioning()` methods to enable seamless integration of SDK and WYF. For further details, please refer to the following link: https://situm.com/docs/wyf-sdk-coexistence/
* Now `onEnterGeofences` and `onExitGeofences` also works in iOS.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,18 @@ Situm SDK for Android now compiles and targets sdkVersion 31 (Android 12). To wo

This plugin is compatible with Capacitor 3.0.

**Issue**: In iOS, there is a known issue with capacitor-cli 3.2.5 and static cordova plugins https://github.com/ionic-team/capacitor/issues/5142. To solve it use a different version of capacitor cli.


**Issue**: In iOS, there is a known issue with capacitor-cli 3.2.5 and static cordova plugins https://github.com/ionic-team/capacitor/issues/5142. To solve it use a different version of capacitor cli.

If the problem persists, add this plugin to the `staticPlugins` section of your `capacitor.config.json` file:
```json
{
"cordova": {
"staticPlugins": [
"situm-cordova-plugin-official"
]
}
}
```


## More information
Expand Down
2 changes: 1 addition & 1 deletion iosSDK.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.58.0
2.59.0
4 changes: 3 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<framework src="libz.dylib" />
<framework src="libc++.dylib" />

<framework src="SitumSDK" type="podspec" spec="2.58.0" />
<framework src="SitumSDK" type="podspec" spec="2.59.0" />


<header-file src="src/ios/situmcordovaplugin/SitumPlugin.h" />
Expand All @@ -79,6 +79,8 @@
<source-file src="src/ios/situmcordovaplugin/SitumPlugin.m" />
<source-file src="src/ios/situmcordovaplugin/SitumLocationWrapper.m" />
<source-file src="src/ios/situmcordovaplugin/Constants.m" />
<source-file src="src/ios/situmcordovaplugin/SITUtils.m" />
<source-file src="src/ios/situmcordovaplugin/SITUtils.h" />

</platform>
</plugin>
94 changes: 49 additions & 45 deletions src/android/app/src/main/java/es/situm/plugin/PluginHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.json.JSONObject;

import java.util.Collection;
import java.util.List;
import java.util.HashMap;
import java.util.List;

import es.situm.sdk.SitumSdk;
import es.situm.sdk.communication.CommunicationManager;
Expand All @@ -29,22 +29,21 @@
import es.situm.sdk.location.LocationRequest;
import es.situm.sdk.location.LocationStatus;
import es.situm.sdk.model.cartography.Building;
import es.situm.sdk.model.cartography.BuildingInfo;
import es.situm.sdk.model.cartography.Floor;
import es.situm.sdk.model.cartography.Geofence;
import es.situm.sdk.model.cartography.Poi;
import es.situm.sdk.model.cartography.PoiCategory;
import es.situm.sdk.model.cartography.Geofence;
import es.situm.sdk.model.cartography.BuildingInfo;
import es.situm.sdk.model.directions.Route;
import es.situm.sdk.model.location.Location;
import es.situm.sdk.model.navigation.NavigationProgress;
import es.situm.sdk.model.realtime.RealTimeData;
import es.situm.sdk.navigation.NavigationListener;
import es.situm.sdk.navigation.NavigationManager;
import es.situm.sdk.navigation.NavigationRequest;
import es.situm.sdk.realtime.RealTimeListener;
import es.situm.sdk.realtime.RealTimeManager;
import es.situm.sdk.realtime.RealTimeRequest;
import es.situm.sdk.realtime.RealTimeListener;
import es.situm.sdk.model.realtime.RealTimeData;

import es.situm.sdk.utils.Handler;
import es.situm.sdk.v1.SitumEvent;

Expand Down Expand Up @@ -143,7 +142,7 @@ public void onFailure(Error error) {

// building, floors, events, indoorPois, outdoorPois, ¿geofences? ¿Paths?
public void fetchBuildingInfo(CordovaInterface cordova, CordovaWebView webView, JSONArray args,
final CallbackContext callbackContext)
final CallbackContext callbackContext)
{
try {
JSONObject jsonoBuilding = args.getJSONObject(0);
Expand All @@ -154,8 +153,8 @@ public void fetchBuildingInfo(CordovaInterface cordova, CordovaWebView webView,
public void onSuccess(BuildingInfo object) {
try {
Log.d(PluginHelper.TAG, "onSuccess: building info fetched successfully.");


JSONObject jsonObject = SitumMapper.buildingInfoToJsonObject(object); // Include geofences to parse ? This needs to be on sdk

callbackContext.sendPluginResult(new PluginResult(Status.OK, jsonObject));
Expand All @@ -178,7 +177,7 @@ public void onFailure(Error error) {
}

public void fetchGeofencesFromBuilding(CordovaInterface cordova, CordovaWebView webView, JSONArray args,
final CallbackContext callbackContext)
final CallbackContext callbackContext)
{
try {
JSONObject jsonoBuilding = args.getJSONObject(0);
Expand Down Expand Up @@ -228,7 +227,7 @@ public void fetchFloorsFromBuilding(CordovaInterface cordova, CordovaWebView web
public void onSuccess(Collection<Floor> floors) {
try {
Log.d(PluginHelper.TAG, "onSuccess: Floors fetched successfully.");

// TODO 19/11/19: jo.put(FLOORS, arrayFromFloors(buildingInfo.getFloors()));
JSONArray jsonaFloors = new JSONArray();

Expand Down Expand Up @@ -274,7 +273,7 @@ public void onSuccess(Collection<Poi> pois) {
for (Poi poi : pois) {
Log.i(PluginHelper.TAG,
"onSuccess: " + poi.getIdentifier() + " - " + poi.getName() + "-" + poi.getCustomFields());

Log.d(PluginHelper.TAG, "Some log that should appear");
JSONObject jsonoPoi = SitumMapper.poiToJsonObject(poi);
jsonaPois.put(jsonoPoi);
Expand Down Expand Up @@ -504,6 +503,9 @@ public void startPositioning(final CordovaInterface cordova, CordovaWebView webV
LocationRequest locationRequest = SitumMapper.locationRequestJSONObjectToLocationRequest(args);

Log.i(TAG, "startPositioning: starting positioning in " + locationRequest);
if (locationListener != null) {
SitumSdk.locationManager().removeLocationListener(locationListener);
}
locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
try {
Expand Down Expand Up @@ -549,7 +551,8 @@ public void onError(Error error) {
}
};
try {
SitumSdk.locationManager().requestLocationUpdates(locationRequest, locationListener);
SitumSdk.locationManager().addLocationListener(locationListener);
SitumSdk.locationManager().requestLocationUpdates(locationRequest);
} catch (Exception e) {
Log.e(PluginHelper.TAG, "onError() called with: error = [" + e + "]");
}
Expand All @@ -559,20 +562,21 @@ public void onError(Error error) {
}
}

public void stopPositioning(CordovaInterface cordova, CordovaWebView webView, JSONArray args,
public void stopPositioning(
CordovaInterface cordova,
CordovaWebView webView,
JSONArray args,
CallbackContext callbackContext) {
try {
SitumSdk.locationManager().removeUpdates();
} catch (Exception e) {
callbackContext.sendPluginResult(new PluginResult(Status.ERROR, e.getMessage()));
}
if (locationListener != null) {
try {
SitumSdk.locationManager().removeUpdates(locationListener);
locationListener = null;
callbackContext.sendPluginResult(new PluginResult(Status.OK, "Success"));
} catch (Exception e) {
callbackContext.sendPluginResult(new PluginResult(Status.ERROR, e.getMessage()));
}
} else {
Log.i(TAG, "stopPositioning: location listener is not started.");
callbackContext.sendPluginResult(new PluginResult(Status.OK, "Allready disabled"));
SitumSdk.locationManager().removeLocationListener(locationListener);
locationListener = null;
}
callbackContext.sendPluginResult(new PluginResult(Status.OK, "Success"));
}

public void onEnterGeofences(CordovaInterface cordova, CordovaWebView webView, JSONArray args,
Expand Down Expand Up @@ -641,8 +645,8 @@ public void invalidateCache(CallbackContext callbackContext) {
}

public void requestNavigationUpdates(final CordovaInterface cordova,
CordovaWebView webView,
JSONArray args,
CordovaWebView webView,
JSONArray args,
final CallbackContext callbackContext) {
// 1) Parse and check arguments

Expand Down Expand Up @@ -731,8 +735,8 @@ public void onProgress(NavigationProgress progress) {
}
PluginResult result = new PluginResult(Status.OK, jsonProgress ); // TODO: Change this to return an object with valid information
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
callbackContext.sendPluginResult(result);

} catch (Exception e) {
//TODO: handle exception
Log.d(TAG, "On Error parsing progress: " + progress);
Expand All @@ -753,7 +757,7 @@ public void onDestinationReached() {
}
PluginResult result = new PluginResult(Status.OK,jsonResult);
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
callbackContext.sendPluginResult(result);
};

public void onUserOutsideRoute() {
Expand All @@ -767,10 +771,10 @@ public void onUserOutsideRoute() {
}
PluginResult result = new PluginResult(Status.OK,jsonResult);
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
callbackContext.sendPluginResult(result);
}
};

// 3) Connect interfaces and connect callback back to js
getNavigationManagerInstance().requestNavigationUpdates(navigationRequest, navigationListener); // Be carefull with exceptions

Expand All @@ -781,9 +785,9 @@ public void onUserOutsideRoute() {
}

public void requestRealTimeUpdates(final CordovaInterface cordova,
CordovaWebView webView,
JSONArray args,
final CallbackContext callbackContext) {
CordovaWebView webView,
JSONArray args,
final CallbackContext callbackContext) {
try {
// Convert request to native
JSONObject jsonRequest = args.getJSONObject(0);
Expand All @@ -792,7 +796,7 @@ public void requestRealTimeUpdates(final CordovaInterface cordova,
// Call

realtimeListener = new RealTimeListener() {

@Override
public void onUserLocations(RealTimeData realTimeData) {
Log.d(TAG, "Success retrieving realtime data" + realTimeData);
Expand All @@ -804,12 +808,12 @@ public void onUserLocations(RealTimeData realTimeData) {
// Send it back to (removing user information)
PluginResult result = new PluginResult(Status.OK,jsonResult);
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
callbackContext.sendPluginResult(result);
} catch (Exception e) {
Log.d(TAG, "Error exception realtime data" + e);
}


}

@Override
Expand All @@ -835,8 +839,8 @@ public void onError(Error error) {
}

public void removeRealTimeUpdates(CordovaInterface cordova,
CordovaWebView webView,
JSONArray args,
CordovaWebView webView,
JSONArray args,
final CallbackContext callbackContext) {
//
Log.i(TAG, "Remove realtime updates");
Expand All @@ -846,8 +850,8 @@ public void removeRealTimeUpdates(CordovaInterface cordova,
// Initialize Navigation Component

public void updateNavigationWithLocation(CordovaInterface cordova,
CordovaWebView webView,
JSONArray args,
CordovaWebView webView,
JSONArray args,
final CallbackContext callbackContext) {
try {
// 1) Check for location arguments
Expand All @@ -859,7 +863,7 @@ public void updateNavigationWithLocation(CordovaInterface cordova,
Log.i(TAG, "UpdateNavigation with Location: " + actualLocation);

// 3) Connect interfaces
getNavigationManagerInstance().updateWithLocation(actualLocation);
getNavigationManagerInstance().updateWithLocation(actualLocation);
callbackContext.sendPluginResult(new PluginResult(Status.OK, "Navigation updated"));
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -868,8 +872,8 @@ public void updateNavigationWithLocation(CordovaInterface cordova,
}

public void removeNavigationUpdates(CordovaInterface cordova,
CordovaWebView webView,
JSONArray args,
CordovaWebView webView,
JSONArray args,
final CallbackContext callbackContext) {
//
Log.i(TAG, "Remove navigation updates");
Expand Down
2 changes: 1 addition & 1 deletion src/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
target 'SitumCordovaPlugin' do
use_frameworks!
platform :ios, '9.0'
pod 'SitumSDK', '2.58.0'
pod 'SitumSDK', '2.59.0'
end
7 changes: 7 additions & 0 deletions src/ios/situmcordovaplugin/SITUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import <SitumSDK/SitumSDK.h>

@interface SITUtils : NSObject

+ (NSArray<NSDictionary *> *) toArrayDict:(NSArray<NSObject<SITMapperProtocol> *> *) objects;

@end
13 changes: 13 additions & 0 deletions src/ios/situmcordovaplugin/SITUtils.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import "SITUtils.h"

@implementation SITUtils

+ (NSArray<NSDictionary *> *) toArrayDict:(NSArray<NSObject<SITMapperProtocol> *> *) objects {
NSMutableArray *exportedArray = [NSMutableArray new];
for (NSObject<SITMapperProtocol> * o in objects) {
[exportedArray addObject:o.toDictionary];
}
return exportedArray;
}

@end
4 changes: 2 additions & 2 deletions src/ios/situmcordovaplugin/SitumPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#import <SitumSDK/SitumSDK.h>


@interface SitumPlugin : CDVPlugin<SITDirectionsDelegate, SITLocationDelegate, SITNavigationDelegate, SITRealTimeDelegate> {
@interface SitumPlugin : CDVPlugin<SITDirectionsDelegate, SITLocationDelegate, SITNavigationDelegate, SITRealTimeDelegate, SITGeofencesDelegate> {

NSMutableDictionary *buildingsStored;
NSMutableDictionary *floorStored;
Expand All @@ -11,7 +11,7 @@
NSMutableDictionary<NSString *, SITPOI*> *poisStored;
NSMutableDictionary *routesStored;

NSString *locationCallbackId, *routeCallbackId, *navigationProgressCallbackId, *realtimeCallbackId;
NSString *locationCallbackId, *routeCallbackId, *navigationProgressCallbackId, *realtimeCallbackId, *enterGeofencesCallbackId, *exitGeofencesCallbackId;
}

// The hooks for our plugin commands
Expand Down
Loading