@situm/react-native 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +656 -0
- package/ReactNativeSitumPlugin.podspec +22 -0
- package/SECURITY-POLICY.md +9 -0
- package/android/.gradle/5.6.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/5.6.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/5.6.4/gc.properties +0 -0
- package/android/.idea/.name +1 -0
- package/android/.idea/codeStyles/Project.xml +116 -0
- package/android/.idea/encodings.xml +6 -0
- package/android/.idea/misc.xml +31 -0
- package/android/.idea/sonarlint/issuestore/index.pb +15 -0
- package/android/.project +34 -0
- package/android/build.gradle +45 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +6 -0
- package/android/gradlew +172 -0
- package/android/gradlew.bat +84 -0
- package/android/src/main/AndroidManifest.xml +6 -0
- package/android/src/main/java/com/situm/plugin/PluginHelper.java +989 -0
- package/android/src/main/java/com/situm/plugin/SitumMapper.java +1206 -0
- package/android/src/main/java/com/situm/plugin/SitumPackage.java +29 -0
- package/android/src/main/java/com/situm/plugin/SitumPlugin.java +84 -0
- package/android/src/main/java/com/situm/plugin/SitumPluginImpl.java +344 -0
- package/android/src/main/java/com/situm/plugin/utils/ReactNativeJson.java +122 -0
- package/android/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/android/src/main/res/values/strings.xml +3 -0
- package/android/src/main/res/values/styles.xml +9 -0
- package/ios/Constants.h +14 -0
- package/ios/Constants.m +14 -0
- package/ios/RNSitumReactNativePlugin.xcodeproj/project.pbxproj +272 -0
- package/ios/SitumLocationWrapper.h +112 -0
- package/ios/SitumLocationWrapper.m +1132 -0
- package/ios/SitumPlugin.h +15 -0
- package/ios/SitumPlugin.m +911 -0
- package/lib/commonjs/index.js +25 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/sdk/index.js +399 -0
- package/lib/commonjs/sdk/index.js.map +1 -0
- package/lib/commonjs/sdk/nativeInterface.js +20 -0
- package/lib/commonjs/sdk/nativeInterface.js.map +1 -0
- package/lib/commonjs/sdk/types/index.d.js +6 -0
- package/lib/commonjs/sdk/types/index.d.js.map +1 -0
- package/lib/commonjs/sdk/utils.js +22 -0
- package/lib/commonjs/sdk/utils.js.map +1 -0
- package/lib/commonjs/utils/requestPermission.js +73 -0
- package/lib/commonjs/utils/requestPermission.js.map +1 -0
- package/lib/commonjs/wayfinding/components/MapView.js +220 -0
- package/lib/commonjs/wayfinding/components/MapView.js.map +1 -0
- package/lib/commonjs/wayfinding/hooks/index.js +401 -0
- package/lib/commonjs/wayfinding/hooks/index.js.map +1 -0
- package/lib/commonjs/wayfinding/index.js +45 -0
- package/lib/commonjs/wayfinding/index.js.map +1 -0
- package/lib/commonjs/wayfinding/store/index.js +237 -0
- package/lib/commonjs/wayfinding/store/index.js.map +1 -0
- package/lib/commonjs/wayfinding/store/utils.js +44 -0
- package/lib/commonjs/wayfinding/store/utils.js.map +1 -0
- package/lib/commonjs/wayfinding/styles/colors.js +18 -0
- package/lib/commonjs/wayfinding/styles/colors.js.map +1 -0
- package/lib/commonjs/wayfinding/types/index.d.js +6 -0
- package/lib/commonjs/wayfinding/types/index.d.js.map +1 -0
- package/lib/commonjs/wayfinding/utils/index.js +11 -0
- package/lib/commonjs/wayfinding/utils/index.js.map +1 -0
- package/lib/commonjs/wayfinding/utils/mapper.js +106 -0
- package/lib/commonjs/wayfinding/utils/mapper.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/sdk/index.js +390 -0
- package/lib/module/sdk/index.js.map +1 -0
- package/lib/module/sdk/nativeInterface.js +18 -0
- package/lib/module/sdk/nativeInterface.js.map +1 -0
- package/lib/module/sdk/types/index.d.js +2 -0
- package/lib/module/sdk/types/index.d.js.map +1 -0
- package/lib/module/sdk/utils.js +15 -0
- package/lib/module/sdk/utils.js.map +1 -0
- package/lib/module/utils/requestPermission.js +67 -0
- package/lib/module/utils/requestPermission.js.map +1 -0
- package/lib/module/wayfinding/components/MapView.js +207 -0
- package/lib/module/wayfinding/components/MapView.js.map +1 -0
- package/lib/module/wayfinding/hooks/index.js +392 -0
- package/lib/module/wayfinding/hooks/index.js.map +1 -0
- package/lib/module/wayfinding/index.js +12 -0
- package/lib/module/wayfinding/index.js.map +1 -0
- package/lib/module/wayfinding/store/index.js +202 -0
- package/lib/module/wayfinding/store/index.js.map +1 -0
- package/lib/module/wayfinding/store/utils.js +34 -0
- package/lib/module/wayfinding/store/utils.js.map +1 -0
- package/lib/module/wayfinding/styles/colors.js +11 -0
- package/lib/module/wayfinding/styles/colors.js.map +1 -0
- package/lib/module/wayfinding/types/index.d.js +2 -0
- package/lib/module/wayfinding/types/index.d.js.map +1 -0
- package/lib/module/wayfinding/utils/index.js +4 -0
- package/lib/module/wayfinding/utils/index.js.map +1 -0
- package/lib/module/wayfinding/utils/mapper.js +100 -0
- package/lib/module/wayfinding/utils/mapper.js.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/sdk/index.d.ts +269 -0
- package/lib/typescript/src/sdk/index.d.ts.map +1 -0
- package/lib/typescript/src/sdk/nativeInterface.d.ts +2 -0
- package/lib/typescript/src/sdk/nativeInterface.d.ts.map +1 -0
- package/lib/typescript/src/sdk/utils.d.ts +7 -0
- package/lib/typescript/src/sdk/utils.d.ts.map +1 -0
- package/lib/typescript/src/utils/requestPermission.d.ts +3 -0
- package/lib/typescript/src/utils/requestPermission.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/components/MapView.d.ts +36 -0
- package/lib/typescript/src/wayfinding/components/MapView.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/hooks/index.d.ts +53 -0
- package/lib/typescript/src/wayfinding/hooks/index.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/index.d.ts +5 -0
- package/lib/typescript/src/wayfinding/index.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/store/index.d.ts +103 -0
- package/lib/typescript/src/wayfinding/store/index.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/store/utils.d.ts +9 -0
- package/lib/typescript/src/wayfinding/store/utils.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/styles/colors.d.ts +8 -0
- package/lib/typescript/src/wayfinding/styles/colors.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/utils/index.d.ts +3 -0
- package/lib/typescript/src/wayfinding/utils/index.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/utils/mapper.d.ts +17 -0
- package/lib/typescript/src/wayfinding/utils/mapper.d.ts.map +1 -0
- package/package.json +130 -0
- package/security.txt +4 -0
- package/src/index.ts +6 -0
- package/src/sdk/index.ts +656 -0
- package/src/sdk/nativeInterface.ts +18 -0
- package/src/sdk/types/index.d.ts +718 -0
- package/src/sdk/utils.ts +16 -0
- package/src/utils/requestPermission.ts +94 -0
- package/src/wayfinding/components/MapView.tsx +312 -0
- package/src/wayfinding/hooks/index.ts +539 -0
- package/src/wayfinding/index.tsx +11 -0
- package/src/wayfinding/store/index.tsx +254 -0
- package/src/wayfinding/store/utils.ts +40 -0
- package/src/wayfinding/styles/colors.tsx +6 -0
- package/src/wayfinding/types/index.d.ts +56 -0
- package/src/wayfinding/utils/index.ts +5 -0
- package/src/wayfinding/utils/mapper.ts +129 -0
|
@@ -0,0 +1,911 @@
|
|
|
1
|
+
#import "SitumPlugin.h"
|
|
2
|
+
#import "SitumLocationWrapper.h"
|
|
3
|
+
|
|
4
|
+
#import <React/RCTAssert.h>
|
|
5
|
+
#import <React/RCTBridge.h>
|
|
6
|
+
#import <React/RCTConvert.h>
|
|
7
|
+
#import <React/RCTEventDispatcher.h>
|
|
8
|
+
#import <React/RCTLog.h>
|
|
9
|
+
|
|
10
|
+
typedef NS_ENUM(NSInteger, RNCSitumAuthorizationLevel) {
|
|
11
|
+
RNCSitumAuthorizationLevelDefault,
|
|
12
|
+
RNCSitumAuthorizationLevelWhenInUse,
|
|
13
|
+
RNCSitumAuthorizationLevelAlways,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
typedef struct {
|
|
17
|
+
BOOL skipPermissionRequests;
|
|
18
|
+
RNCSitumAuthorizationLevel authorizationLevel;
|
|
19
|
+
} RNCSitumConfiguration;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@implementation RCTConvert (RNCSitumAuthorizationLevel)
|
|
23
|
+
RCT_ENUM_CONVERTER(RNCSitumAuthorizationLevel, (@{
|
|
24
|
+
@"whenInUse": @(RNCSitumAuthorizationLevelWhenInUse),
|
|
25
|
+
@"always": @(RNCSitumAuthorizationLevelAlways)}),
|
|
26
|
+
RNCSitumAuthorizationLevelDefault, integerValue)
|
|
27
|
+
@end
|
|
28
|
+
|
|
29
|
+
@implementation RCTConvert(RNCSitumConfiguration)
|
|
30
|
+
|
|
31
|
+
+ (RNCSitumConfiguration)RNCSitumConfiguration:(id)json
|
|
32
|
+
{
|
|
33
|
+
NSDictionary<NSString *, id> *options = [RCTConvert NSDictionary:json];
|
|
34
|
+
|
|
35
|
+
return (RNCSitumConfiguration) {
|
|
36
|
+
.skipPermissionRequests = [RCTConvert BOOL:options[@"skipPermissionRequests"]],
|
|
37
|
+
.authorizationLevel = [RCTConvert RNCSitumAuthorizationLevel:options[@"authorizationLevel"]]
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@end
|
|
42
|
+
|
|
43
|
+
static NSString *ResultsKey = @"results";
|
|
44
|
+
|
|
45
|
+
static NSString *StartingAngle=@"startingAngle";
|
|
46
|
+
static NSString *Accessible=@"accessible";
|
|
47
|
+
|
|
48
|
+
static BOOL IS_LOG_ENABLED = NO;
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
static NSString *DEFAULT_SITUM_LOG = @"SitumSDK >>: ";
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@interface RNCSitumRequest : NSObject
|
|
55
|
+
|
|
56
|
+
@property (nonatomic, copy) RCTResponseSenderBlock successBlock;
|
|
57
|
+
@property (nonatomic, copy) RCTResponseSenderBlock errorBlock;
|
|
58
|
+
|
|
59
|
+
@end
|
|
60
|
+
|
|
61
|
+
@implementation RNCSitumRequest
|
|
62
|
+
|
|
63
|
+
@end
|
|
64
|
+
|
|
65
|
+
@interface SitumPlugin() {}
|
|
66
|
+
|
|
67
|
+
@property (nonatomic, strong) SITRoute *computedRoute;
|
|
68
|
+
|
|
69
|
+
@end
|
|
70
|
+
|
|
71
|
+
@implementation SitumPlugin
|
|
72
|
+
|
|
73
|
+
BOOL _positioningUpdates, _navigationUpdates, _realtimeUpdates;
|
|
74
|
+
CLLocationManager *_locationManager;
|
|
75
|
+
RNCSitumConfiguration _locationConfiguration;
|
|
76
|
+
RNCSitumRequest *routeRequest;
|
|
77
|
+
|
|
78
|
+
RCT_EXPORT_MODULE(RNCSitumPlugin);
|
|
79
|
+
|
|
80
|
+
- (dispatch_queue_t)methodQueue
|
|
81
|
+
{
|
|
82
|
+
return dispatch_get_main_queue();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
- (NSArray<NSString *> *)supportedEvents
|
|
86
|
+
{
|
|
87
|
+
return @[@"locationChanged", @"statusChanged", @"locationError", @"navigationUpdated", @"navigationError", @"realtimeUpdated", @"realtimeError", @"onEnterGeofences", @"onExitGeofences"];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@synthesize computedRoute = _computedRoute;
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
RCT_EXPORT_METHOD(initSitumSDK)
|
|
94
|
+
{
|
|
95
|
+
// only specific to Android at the moment
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
RCT_EXPORT_METHOD(setUseRemoteConfig:(NSString *)useRemoteConfig withCallback:(RCTResponseSenderBlock)callback) {
|
|
99
|
+
[SITServices setUseRemoteConfig:([useRemoteConfig isEqualToString:@"true"] ? YES: NO)];
|
|
100
|
+
if (callback) {
|
|
101
|
+
NSDictionary *response = @{@"success": @"true"};
|
|
102
|
+
callback(@[response]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
RCT_EXPORT_METHOD(setApiKey:(NSString *)email apiKey:(NSString *)apiKey withCallback:(RCTResponseSenderBlock)callback)
|
|
107
|
+
{
|
|
108
|
+
BOOL success = [SITServices provideAPIKey:apiKey forEmail:email];
|
|
109
|
+
|
|
110
|
+
NSDictionary *response = @{@"success":success ? @"true" : @"false"};
|
|
111
|
+
if(callback)
|
|
112
|
+
callback(@[response]);
|
|
113
|
+
|
|
114
|
+
if (IS_LOG_ENABLED) {
|
|
115
|
+
NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
116
|
+
NSString *documentsDirectory = [allPaths objectAtIndex:0];
|
|
117
|
+
NSString *pathForLog = [documentsDirectory stringByAppendingPathComponent:@"logging.txt"];
|
|
118
|
+
freopen([pathForLog cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
|
|
119
|
+
|
|
120
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ Logging ios calls", DEFAULT_SITUM_LOG]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
RCT_EXPORT_METHOD(setUserPass:(NSString *)email pass:(NSString *)pass withCallback:(RCTResponseSenderBlock)callback)
|
|
125
|
+
{
|
|
126
|
+
BOOL success =[SITServices provideUser:email password:pass];
|
|
127
|
+
|
|
128
|
+
NSDictionary *response = @{@"success":success ? @"true" : @"false"};
|
|
129
|
+
if(callback)
|
|
130
|
+
callback(@[response]);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
RCT_EXPORT_METHOD(setDashboardURL:(NSString *)url withCallback:(RCTResponseSenderBlock)callback) {
|
|
134
|
+
BOOL success = NO;
|
|
135
|
+
|
|
136
|
+
if (url && url.length) {
|
|
137
|
+
success = YES;
|
|
138
|
+
[SITServices setDashboardURL:url];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (callback) {
|
|
142
|
+
NSDictionary *response = @{@"success":success ? @"true" : @"false"};
|
|
143
|
+
callback(@[response]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
RCT_EXPORT_METHOD(setCacheMaxAge:(nonnull NSNumber *)cacheMaxAge withCallback:(RCTResponseSenderBlock)callback)
|
|
148
|
+
{
|
|
149
|
+
[[SITCommunicationManager sharedManager] setCacheMaxAge:[cacheMaxAge integerValue]];
|
|
150
|
+
NSString *operation = [NSString stringWithFormat:@"Setting cache max age to :%@ seconds", cacheMaxAge];
|
|
151
|
+
|
|
152
|
+
if (IS_LOG_ENABLED) {
|
|
153
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ ", DEFAULT_SITUM_LOG, operation]);
|
|
154
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ Cache max age is %ld seconds", DEFAULT_SITUM_LOG, (long)[[SITCommunicationManager sharedManager] cacheMaxAge]]);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// return operation, because iOS SDK doesn't return a boolean value when setting max cache
|
|
158
|
+
NSDictionary *response = @{@"success": operation};
|
|
159
|
+
if(callback)
|
|
160
|
+
callback(@[response]);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
RCT_EXPORT_METHOD(fetchBuildings: (RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
164
|
+
{
|
|
165
|
+
if (buildingsStored == nil) {
|
|
166
|
+
buildingsStored = [[NSMutableDictionary alloc] init];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
NSString *operation = @"Fetching buildings request";
|
|
170
|
+
if (IS_LOG_ENABLED) {
|
|
171
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ ", DEFAULT_SITUM_LOG, operation]);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
[[SITCommunicationManager sharedManager] fetchBuildingsWithOptions:nil success:^(NSDictionary *mapping) {
|
|
175
|
+
if (IS_LOG_ENABLED) {
|
|
176
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ Fetching buildings returned values", DEFAULT_SITUM_LOG, operation]);
|
|
177
|
+
}
|
|
178
|
+
NSArray *buildings = [mapping valueForKey:ResultsKey];
|
|
179
|
+
|
|
180
|
+
if (buildings.count == 0) {
|
|
181
|
+
if (IS_LOG_ENABLED) {
|
|
182
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ No buildings were retrieved", DEFAULT_SITUM_LOG, operation]);
|
|
183
|
+
}
|
|
184
|
+
if(errorBlock)
|
|
185
|
+
errorBlock(@[@"There are no buildings on the account. Please go to dashboard http://dashboard.situm.es and learn more about the first step with Situm technology"]);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
NSMutableArray *ja = [[NSMutableArray alloc] init];
|
|
189
|
+
for (SITBuilding *obj in buildings) {
|
|
190
|
+
[ja addObject:[SitumLocationWrapper.shared buildingToJsonObject:obj]];
|
|
191
|
+
[buildingsStored setObject:obj forKey:[NSString stringWithFormat:@"%@", obj.identifier]];
|
|
192
|
+
}
|
|
193
|
+
if (IS_LOG_ENABLED) {
|
|
194
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ Retrieved the following buildings: %@", DEFAULT_SITUM_LOG, operation, buildings]);
|
|
195
|
+
}
|
|
196
|
+
successBlock(@[ja.copy]);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
failure:^(NSError *error) {
|
|
200
|
+
if (IS_LOG_ENABLED)
|
|
201
|
+
{
|
|
202
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ Error retrieving buildings: %@", DEFAULT_SITUM_LOG, operation, error]);
|
|
203
|
+
}
|
|
204
|
+
if(errorBlock)
|
|
205
|
+
errorBlock(@[error.description]);
|
|
206
|
+
}];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
RCT_EXPORT_METHOD(fetchTilesFromBuilding:(NSDictionary *)buildingJO withSuccessCallback:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
210
|
+
{
|
|
211
|
+
NSString *operation = @"Fetching tiles from building request";
|
|
212
|
+
if (IS_LOG_ENABLED) {
|
|
213
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ with parameters: %@", DEFAULT_SITUM_LOG, operation, buildingJO]);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
NSString *buildingId = [buildingJO valueForKey:@"identifier"];
|
|
217
|
+
|
|
218
|
+
[[SITCommunicationManager sharedManager] fetchTilesForBuilding:buildingId success:^(NSDictionary * _Nullable mapping) {
|
|
219
|
+
if (IS_LOG_ENABLED) {
|
|
220
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ retrieved tiles from building: %@ with result: %@", DEFAULT_SITUM_LOG, operation, buildingJO, mapping]);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
successBlock(@[mapping]);
|
|
224
|
+
|
|
225
|
+
} failure:^(NSError * _Nullable error) {
|
|
226
|
+
if (IS_LOG_ENABLED) {
|
|
227
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ error : %@ retrieving building info on building: %@", DEFAULT_SITUM_LOG, operation, error, buildingId]);
|
|
228
|
+
}
|
|
229
|
+
if(errorBlock)
|
|
230
|
+
errorBlock(@[error.description]);
|
|
231
|
+
}];
|
|
232
|
+
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
RCT_EXPORT_METHOD(fetchBuildingInfo:(NSDictionary *)buildingJO withSuccessCallback:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
236
|
+
{
|
|
237
|
+
|
|
238
|
+
NSString *operation = @"Fetching building info request";
|
|
239
|
+
if (IS_LOG_ENABLED) {
|
|
240
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ with parameters: %@", DEFAULT_SITUM_LOG, operation, buildingJO]);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
NSString *buildingId = [buildingJO valueForKey:@"identifier"];
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
[[SITCommunicationManager sharedManager] fetchBuildingInfo:buildingId withOptions:nil success:^(NSDictionary * _Nullable mapping) {
|
|
247
|
+
if (IS_LOG_ENABLED) {
|
|
248
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ Fetching buildings returned values", DEFAULT_SITUM_LOG, operation]);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Parse and convert to json
|
|
252
|
+
NSDictionary *buildingInfoJson = [SitumLocationWrapper.shared buildingInfoToJsonObject:mapping[@"results"]];
|
|
253
|
+
|
|
254
|
+
// Send result outsidecon e
|
|
255
|
+
if (IS_LOG_ENABLED) {
|
|
256
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ retrieved building info: %@ of building: %@", DEFAULT_SITUM_LOG, operation, buildingInfoJson, buildingJO]);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
successBlock(@[buildingInfoJson.copy]);
|
|
260
|
+
|
|
261
|
+
} failure:^(NSError * _Nullable error) {
|
|
262
|
+
if (IS_LOG_ENABLED) {
|
|
263
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ error : %@ retrieving building info on building: %@", DEFAULT_SITUM_LOG, operation, error, buildingId]);
|
|
264
|
+
}
|
|
265
|
+
if(errorBlock)
|
|
266
|
+
errorBlock(@[error.description]);
|
|
267
|
+
}];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
RCT_EXPORT_METHOD(fetchFloorsFromBuilding:(NSDictionary *)buildingJO withSuccessCallback:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
271
|
+
{
|
|
272
|
+
|
|
273
|
+
NSString *operation = @"Fetching floors request";
|
|
274
|
+
if (IS_LOG_ENABLED) {
|
|
275
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ with parameters: %@", DEFAULT_SITUM_LOG, operation, buildingJO]);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (floorStored == nil) {
|
|
279
|
+
floorStored = [[NSMutableDictionary alloc] init];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
NSString *buildingId = [buildingJO valueForKey:@"identifier"];
|
|
283
|
+
__block BOOL success;
|
|
284
|
+
[[SITCommunicationManager sharedManager] fetchFloorsForBuilding:buildingId withOptions:nil success:^(NSDictionary *mapping) {
|
|
285
|
+
|
|
286
|
+
if (IS_LOG_ENABLED) {
|
|
287
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ responded", DEFAULT_SITUM_LOG, operation]);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
NSMutableArray *ja = [[NSMutableArray alloc] init];
|
|
291
|
+
NSArray *floors = [mapping objectForKey:@"results"];
|
|
292
|
+
if (IS_LOG_ENABLED) {
|
|
293
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ results: %@", DEFAULT_SITUM_LOG, operation, floors]);
|
|
294
|
+
}
|
|
295
|
+
for (SITFloor *obj in floors) {
|
|
296
|
+
NSDictionary *floorJson = [SitumLocationWrapper.shared floorToJsonObject:obj];
|
|
297
|
+
if (IS_LOG_ENABLED) {
|
|
298
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ parsed floor: %@", DEFAULT_SITUM_LOG, operation, floorJson]);
|
|
299
|
+
}
|
|
300
|
+
[ja addObject:floorJson];
|
|
301
|
+
if (IS_LOG_ENABLED) {
|
|
302
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ json array has : %@", DEFAULT_SITUM_LOG, operation, ja]);
|
|
303
|
+
}
|
|
304
|
+
[floorStored setObject:obj forKey:[NSString stringWithFormat:@"%@", obj.identifier]];
|
|
305
|
+
if (IS_LOG_ENABLED) {
|
|
306
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ added: %@ to dictionary results", DEFAULT_SITUM_LOG, operation, obj]);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (floors.count == 0) {
|
|
310
|
+
if (IS_LOG_ENABLED) {
|
|
311
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ no floors on building: %@", DEFAULT_SITUM_LOG, operation, buildingJO]);
|
|
312
|
+
}
|
|
313
|
+
if(errorBlock)
|
|
314
|
+
errorBlock(@[@"The selected building does not have floors. Correct that on http://dashboard.situm.es"]);
|
|
315
|
+
} else {
|
|
316
|
+
if (IS_LOG_ENABLED) {
|
|
317
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ retrieved floors: %@ on building: %@", DEFAULT_SITUM_LOG, operation, floors, buildingJO]);
|
|
318
|
+
}
|
|
319
|
+
if(!success){
|
|
320
|
+
successBlock(@[ja.copy]);
|
|
321
|
+
success = YES;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
} failure:^(NSError *error) {
|
|
325
|
+
if (IS_LOG_ENABLED) {
|
|
326
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ error : %@ retrieving floors on building: %@", DEFAULT_SITUM_LOG, operation, error, buildingJO]);
|
|
327
|
+
}
|
|
328
|
+
if(errorBlock)
|
|
329
|
+
errorBlock(@[error.description]);
|
|
330
|
+
}];
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
RCT_EXPORT_METHOD(fetchMapFromFloor:(NSDictionary *)floorJO withSuccessCallback:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
334
|
+
{
|
|
335
|
+
|
|
336
|
+
if (floorStored == nil) {
|
|
337
|
+
floorStored = [[NSMutableDictionary alloc] init];
|
|
338
|
+
}
|
|
339
|
+
SITFloor* floor = [SitumLocationWrapper.shared jsonObjectToFloor:floorJO];
|
|
340
|
+
|
|
341
|
+
[[SITCommunicationManager sharedManager] fetchMapFromFloor: floor withCompletion:^(NSData *imageData) {
|
|
342
|
+
NSMutableDictionary *jaMap = [[NSMutableDictionary alloc] init];
|
|
343
|
+
NSString *imageBase64Encoded = [imageData base64EncodedStringWithOptions:0];
|
|
344
|
+
successBlock(@[imageBase64Encoded]);
|
|
345
|
+
}];
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
RCT_EXPORT_METHOD(startPositioning:(NSDictionary *)request)
|
|
349
|
+
{
|
|
350
|
+
SITLocationRequest *locationRequest = [SitumLocationWrapper.shared dictToLocationRequest:request];
|
|
351
|
+
|
|
352
|
+
_positioningUpdates = YES;
|
|
353
|
+
[[SITLocationManager sharedInstance] addDelegate:self];
|
|
354
|
+
[[SITLocationManager sharedInstance] requestLocationUpdates:locationRequest];
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
RCT_EXPORT_METHOD(stopPositioning:(RCTResponseSenderBlock)callback)
|
|
358
|
+
{
|
|
359
|
+
_positioningUpdates = NO;
|
|
360
|
+
[[SITLocationManager sharedInstance] removeUpdates];
|
|
361
|
+
[[SITLocationManager sharedInstance] removeDelegate:self];
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
RCT_EXPORT_METHOD(requestDirections: (NSArray *)requestArray withSuccessCallback:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
365
|
+
{
|
|
366
|
+
|
|
367
|
+
if (routesStored == nil) {
|
|
368
|
+
routesStored = [[NSMutableDictionary alloc] init];
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
SITDirectionsRequest* directionsRequest = [SitumLocationWrapper.shared jsonObjectToDirectionsRequest:requestArray];
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
if (directionsRequest == nil) {
|
|
375
|
+
errorBlock(@[@"Unable to parse request"]);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
if (IS_LOG_ENABLED) {
|
|
379
|
+
NSLog(@"Start point properties: %@, cartesian coordinate:: x: %f, y: %f, ", directionsRequest.origin, directionsRequest.origin.cartesianCoordinate.x, directionsRequest.origin.cartesianCoordinate.y);
|
|
380
|
+
|
|
381
|
+
NSLog(@"End point properties: %@, cartesian coordinate:: x: %f, y: %f, ", directionsRequest.destination, directionsRequest.destination.cartesianCoordinate.x, directionsRequest.destination.cartesianCoordinate.y);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
routeRequest = [RNCSitumRequest new];
|
|
385
|
+
routeRequest.successBlock = successBlock;
|
|
386
|
+
routeRequest.errorBlock = errorBlock;
|
|
387
|
+
|
|
388
|
+
[SITDirectionsManager sharedInstance].delegate = self;
|
|
389
|
+
[[SITDirectionsManager sharedInstance] requestDirections:directionsRequest];
|
|
390
|
+
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
RCT_EXPORT_METHOD(fetchGeofencesFromBuilding:(NSDictionary *)buildingJO withSuccessCallback:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
394
|
+
{
|
|
395
|
+
NSString *operation = @"Fetching geofences request";
|
|
396
|
+
if (IS_LOG_ENABLED) {
|
|
397
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ with parameters: %@", DEFAULT_SITUM_LOG, operation, buildingJO]);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
NSString *buildingId = [buildingJO valueForKey:@"identifier"];
|
|
401
|
+
SITBuilding *building = [[SITBuilding alloc]init];
|
|
402
|
+
building.identifier = buildingId;
|
|
403
|
+
|
|
404
|
+
[[SITCommunicationManager sharedManager] fetchGeofencesFromBuilding:building
|
|
405
|
+
withOptions:nil
|
|
406
|
+
withCompletion:^(id _Nullable array, NSError * _Nullable error) {
|
|
407
|
+
if (error) {
|
|
408
|
+
if (IS_LOG_ENABLED) {
|
|
409
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ error : %@ retrieving geofences on building: %@", DEFAULT_SITUM_LOG, operation, error, buildingJO]);
|
|
410
|
+
}
|
|
411
|
+
if(errorBlock){
|
|
412
|
+
errorBlock(@[error.description]);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// A success has been returned
|
|
419
|
+
if (IS_LOG_ENABLED) {
|
|
420
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ responded", DEFAULT_SITUM_LOG, operation]);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
NSMutableArray *ja = [[NSMutableArray alloc] init];
|
|
424
|
+
if (IS_LOG_ENABLED) {
|
|
425
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ results: %@", DEFAULT_SITUM_LOG, operation, array]);
|
|
426
|
+
}
|
|
427
|
+
for (SITGeofence *obj in array) {
|
|
428
|
+
NSDictionary *jsonObject = [SitumLocationWrapper.shared geofenceToJsonObject:obj];
|
|
429
|
+
if (IS_LOG_ENABLED) {
|
|
430
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ parsed floor: %@", DEFAULT_SITUM_LOG, operation, jsonObject]);
|
|
431
|
+
}
|
|
432
|
+
[ja addObject:jsonObject];
|
|
433
|
+
if (IS_LOG_ENABLED) {
|
|
434
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ json array has : %@", DEFAULT_SITUM_LOG, operation, ja]);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (IS_LOG_ENABLED) {
|
|
439
|
+
NSLog(@"%@", [NSString stringWithFormat: @"%@ %@ retrieved geofences: %@ on building: %@", DEFAULT_SITUM_LOG, operation, array, buildingJO]);
|
|
440
|
+
}
|
|
441
|
+
successBlock(@[ja.copy]);
|
|
442
|
+
}];
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
RCT_EXPORT_METHOD(fetchPoiCategories:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
446
|
+
{
|
|
447
|
+
if (categoryStored == nil) {
|
|
448
|
+
categoryStored = [[NSMutableDictionary alloc] init];
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
[[SITCommunicationManager sharedManager] fetchCategoriesWithOptions:nil withCompletion:^(NSArray *categories, NSError *error) {
|
|
452
|
+
if (!error) {
|
|
453
|
+
NSMutableArray *ja = [[NSMutableArray alloc] init];
|
|
454
|
+
for (SITPOICategory *obj in categories) {
|
|
455
|
+
[ja addObject:[SitumLocationWrapper.shared poiCategoryToJsonObject:obj]];
|
|
456
|
+
[categoryStored setObject:obj forKey:[NSString stringWithFormat:@"%@", obj.name]];
|
|
457
|
+
}
|
|
458
|
+
if (categories.count == 0) {
|
|
459
|
+
if(errorBlock)
|
|
460
|
+
errorBlock(@[@"You have no categories"]);
|
|
461
|
+
} else {
|
|
462
|
+
successBlock(@[ja.copy]);
|
|
463
|
+
}
|
|
464
|
+
} else {
|
|
465
|
+
if(errorBlock)
|
|
466
|
+
errorBlock(@[error.description]);
|
|
467
|
+
}
|
|
468
|
+
}];
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
RCT_EXPORT_METHOD(fetchPoiCategoryIconNormal:(NSDictionary *)categoryJO withSuccessCallback:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
472
|
+
{
|
|
473
|
+
|
|
474
|
+
if (categoryStored == nil) {
|
|
475
|
+
categoryStored = [[NSMutableDictionary alloc] init];
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
SITPOICategory *category = [[SitumLocationWrapper shared] poiCategoryFromJsonObject:categoryJO];
|
|
479
|
+
|
|
480
|
+
[[SITCommunicationManager sharedManager] fetchSelected:false iconForCategory:category withCompletion:^(NSData *data, NSError *error) {
|
|
481
|
+
if (!error) {
|
|
482
|
+
if (data == nil) {
|
|
483
|
+
if(errorBlock){
|
|
484
|
+
errorBlock(@[@"Icon not found"]);
|
|
485
|
+
}
|
|
486
|
+
} else {
|
|
487
|
+
UIImage *icon = [UIImage imageWithData:data];
|
|
488
|
+
NSDictionary * dict = [[SitumLocationWrapper shared] bitmapToJsonObject:icon];
|
|
489
|
+
successBlock(@[dict]);
|
|
490
|
+
}
|
|
491
|
+
} else {
|
|
492
|
+
if(errorBlock){
|
|
493
|
+
errorBlock(@[error.description]);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}];
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
RCT_EXPORT_METHOD(fetchPoiCategoryIconSelected:(NSDictionary *)categoryJO withSuccessCallback:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
500
|
+
{
|
|
501
|
+
if (categoryStored == nil) {
|
|
502
|
+
categoryStored = [[NSMutableDictionary alloc] init];
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
SITPOICategory *category = [[SitumLocationWrapper shared] poiCategoryFromJsonObject:categoryJO];
|
|
506
|
+
|
|
507
|
+
[[SITCommunicationManager sharedManager] fetchSelected:true iconForCategory:category withCompletion:^(NSData *data, NSError *error) {
|
|
508
|
+
if (!error) {
|
|
509
|
+
if (data == nil) {
|
|
510
|
+
if(errorBlock){
|
|
511
|
+
errorBlock(@[@"Icon not found"]);
|
|
512
|
+
}
|
|
513
|
+
} else {
|
|
514
|
+
UIImage *icon = [UIImage imageWithData:data];
|
|
515
|
+
NSDictionary * dict = [[SitumLocationWrapper shared] bitmapToJsonObject:icon];
|
|
516
|
+
successBlock(@[dict]);
|
|
517
|
+
}
|
|
518
|
+
} else {
|
|
519
|
+
if(errorBlock){
|
|
520
|
+
errorBlock(@[error.description]);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}];
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
RCT_EXPORT_METHOD(fetchIndoorPOIsFromBuilding:(NSDictionary *)buildingJO withSuccessCallback:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
527
|
+
{
|
|
528
|
+
|
|
529
|
+
if (poisStored == nil) {
|
|
530
|
+
poisStored = [[NSMutableDictionary alloc] init];
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
[[SITCommunicationManager sharedManager] fetchPoisOfBuilding:[buildingJO valueForKey:@"identifier"] withOptions:nil success:^(NSDictionary *mapping) {
|
|
534
|
+
NSArray *list = [mapping objectForKey:@"results"];
|
|
535
|
+
NSMutableArray *ja = [[NSMutableArray alloc] init];
|
|
536
|
+
for (SITPOI *obj in list) {
|
|
537
|
+
[ja addObject:[SitumLocationWrapper.shared poiToJsonObject:obj]];
|
|
538
|
+
[poisStored setObject:obj forKey:obj.name];
|
|
539
|
+
}
|
|
540
|
+
if (list.count == 0) {
|
|
541
|
+
errorBlock(@[@"You have no poi. Create one in the Dashboard"]);
|
|
542
|
+
} else {
|
|
543
|
+
successBlock(@[ja.copy]);
|
|
544
|
+
}
|
|
545
|
+
} failure:^(NSError *error) {
|
|
546
|
+
errorBlock(@[error.description]);
|
|
547
|
+
}];
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
RCT_EXPORT_METHOD(fetchOutdoorPOIsFromBuilding:(NSDictionary *)buildingJO withSuccessCallback:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
551
|
+
{
|
|
552
|
+
|
|
553
|
+
if (poisStored == nil) {
|
|
554
|
+
poisStored = [[NSMutableDictionary alloc] init];
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
[[SITCommunicationManager sharedManager] fetchOutdoorPoisOfBuilding:[buildingJO valueForKey:@"identifier"] withOptions:nil success:^(NSDictionary *mapping) {
|
|
558
|
+
NSArray *list = [mapping objectForKey:@"results"];
|
|
559
|
+
NSMutableArray *ja = [[NSMutableArray alloc] init];
|
|
560
|
+
for (SITPOI *obj in list) {
|
|
561
|
+
[ja addObject:[SitumLocationWrapper.shared poiToJsonObject:obj]];
|
|
562
|
+
[poisStored setObject:obj forKey:obj.name];
|
|
563
|
+
}
|
|
564
|
+
if (list.count == 0) {
|
|
565
|
+
errorBlock(@[@"You have no poi. Create one in the Dashboard"]);
|
|
566
|
+
} else {
|
|
567
|
+
successBlock(@[ja.copy]);
|
|
568
|
+
}
|
|
569
|
+
} failure:^(NSError *error) {
|
|
570
|
+
errorBlock(@[error.description]);
|
|
571
|
+
}];
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
RCT_EXPORT_METHOD(fetchEventsFromBuilding:(NSDictionary *)buildingJO withSuccessCallback:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
575
|
+
{
|
|
576
|
+
|
|
577
|
+
if (eventStored == nil) {
|
|
578
|
+
eventStored = [[NSMutableDictionary alloc] init];
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
SITBuilding *building = [SITBuilding new];
|
|
582
|
+
building.identifier = buildingJO[@"identifier"];
|
|
583
|
+
|
|
584
|
+
[[SITCommunicationManager sharedManager] fetchEventsFromBuilding:building withOptions:nil withCompletion:^SITHandler(NSArray<SITEvent *> *events, NSError *error) {
|
|
585
|
+
if (!error) {
|
|
586
|
+
NSMutableArray *ja = [[NSMutableArray alloc] init];
|
|
587
|
+
for (SITEvent *obj in events) {
|
|
588
|
+
[ja addObject:[SitumLocationWrapper.shared eventToJsonObject:obj]];
|
|
589
|
+
[eventStored setObject:obj forKey:[NSString stringWithFormat:@"%@", obj.name]];
|
|
590
|
+
}
|
|
591
|
+
if (events.count == 0) {
|
|
592
|
+
errorBlock(@[@"You have no events. Create one in the Dashboard"]);
|
|
593
|
+
} else {
|
|
594
|
+
successBlock(@[ja.copy]);
|
|
595
|
+
}
|
|
596
|
+
} else {
|
|
597
|
+
errorBlock(@[error.description]);
|
|
598
|
+
}
|
|
599
|
+
return false;
|
|
600
|
+
}];
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
RCT_EXPORT_METHOD(requestNavigationUpdates:(NSDictionary *)options)
|
|
604
|
+
{
|
|
605
|
+
NSNumber* distanceToChangeFloorThreshold;
|
|
606
|
+
NSNumber* distanceToChangeIndicationThreshold;
|
|
607
|
+
NSNumber* distanceToGoalThreshold;
|
|
608
|
+
NSNumber* outsideRouteThreshold;
|
|
609
|
+
NSNumber* indicationsInterval;
|
|
610
|
+
NSNumber* timeToFirstIndication;
|
|
611
|
+
NSNumber* roundIndicationsStep;
|
|
612
|
+
NSNumber* timeToIgnoreUnexpectedFloorChanges;
|
|
613
|
+
|
|
614
|
+
// Processing configuration parameters
|
|
615
|
+
distanceToChangeFloorThreshold = (NSNumber*)[options objectForKey:@"distanceToFloorChangeThreshold"];
|
|
616
|
+
distanceToChangeIndicationThreshold = (NSNumber*)[options objectForKey:@"distanceToChangeIndicationThreshold"];
|
|
617
|
+
distanceToGoalThreshold = (NSNumber*)[options objectForKey:@"distanceToGoalThreshold"];
|
|
618
|
+
outsideRouteThreshold = (NSNumber*)[options objectForKey:@"outsideRouteThreshold"];
|
|
619
|
+
indicationsInterval = (NSNumber*)[options objectForKey:@"indicationsInterval"];
|
|
620
|
+
timeToFirstIndication = (NSNumber*)[options objectForKey:@"timeToFirstIndication"];
|
|
621
|
+
roundIndicationsStep = (NSNumber*)[options objectForKey:@"roundIndicationsStep"];
|
|
622
|
+
timeToIgnoreUnexpectedFloorChanges = (NSNumber*)[options objectForKey:@"timeToIgnoreUnexpectedFloorChanges"];
|
|
623
|
+
|
|
624
|
+
SITRoute *routeObj = self.computedRoute;
|
|
625
|
+
if (routeObj) {
|
|
626
|
+
SITNavigationRequest *navigationRequest = [[SITNavigationRequest alloc] initWithRoute:routeObj];
|
|
627
|
+
if (distanceToChangeIndicationThreshold != nil) {
|
|
628
|
+
NSInteger value = [distanceToChangeIndicationThreshold integerValue];
|
|
629
|
+
[navigationRequest setDistanceToChangeIndicationThreshold: value];
|
|
630
|
+
NSLog(@"%@", [NSString stringWithFormat: @"navigationRequest.distanceToChangeIndicationThreshold: %ld", navigationRequest.distanceToChangeIndicationThreshold]);
|
|
631
|
+
}
|
|
632
|
+
if (distanceToChangeFloorThreshold != nil) {
|
|
633
|
+
NSInteger value = [distanceToChangeFloorThreshold integerValue];
|
|
634
|
+
[navigationRequest setDistanceToChangeFloorThreshold: value];
|
|
635
|
+
NSLog(@"%@", [NSString stringWithFormat: @"navigationRequest.distanceToChangeFloorThreshold: %ld", navigationRequest.distanceToFloorChangeThreshold]);
|
|
636
|
+
}
|
|
637
|
+
if (distanceToGoalThreshold != nil) {
|
|
638
|
+
NSInteger value = [distanceToGoalThreshold integerValue];
|
|
639
|
+
[navigationRequest setDistanceToGoalThreshold: value];
|
|
640
|
+
NSLog(@"%@", [NSString stringWithFormat: @"navigationRequest.distanceToGoalThreshold: %ld", navigationRequest.distanceToGoalThreshold]);
|
|
641
|
+
}
|
|
642
|
+
if (outsideRouteThreshold != nil) {
|
|
643
|
+
NSInteger value = [outsideRouteThreshold integerValue];
|
|
644
|
+
[navigationRequest setOutsideRouteThreshold: value];
|
|
645
|
+
NSLog(@"%@", [NSString stringWithFormat: @"navigationRequest.outsideRouteThreshold: %ld", navigationRequest.outsideRouteThreshold]);
|
|
646
|
+
}
|
|
647
|
+
if (indicationsInterval != nil) {
|
|
648
|
+
NSInteger value = [indicationsInterval integerValue];
|
|
649
|
+
[navigationRequest setIndicationsInterval: value];
|
|
650
|
+
NSLog(@"%@", [NSString stringWithFormat: @"navigationRequest.indicationsInterval: %ld", navigationRequest.indicationsInterval]);
|
|
651
|
+
}
|
|
652
|
+
if (timeToFirstIndication != nil) {
|
|
653
|
+
NSInteger value = [timeToFirstIndication integerValue];
|
|
654
|
+
[navigationRequest setTimeToFirstIndication: value];
|
|
655
|
+
NSLog(@"%@", [NSString stringWithFormat: @"navigationRequest.timeToFirstIndication: %ld", navigationRequest.timeToFirstIndication]);
|
|
656
|
+
}
|
|
657
|
+
if (roundIndicationsStep != nil) {
|
|
658
|
+
NSInteger value = [roundIndicationsStep integerValue];
|
|
659
|
+
[navigationRequest setRoundIndicationsStep: value];
|
|
660
|
+
NSLog(@"%@", [NSString stringWithFormat: @"navigationRequest.roundIndicationsStep: %ld", navigationRequest.roundIndicationsStep]);
|
|
661
|
+
}
|
|
662
|
+
if (timeToIgnoreUnexpectedFloorChanges != nil) {
|
|
663
|
+
NSInteger value = [timeToIgnoreUnexpectedFloorChanges integerValue];
|
|
664
|
+
[navigationRequest setTimeToIgnoreUnexpectedFloorChanges: value];
|
|
665
|
+
NSLog(@"%@", [NSString stringWithFormat: @"navigationRequest.timeToIgnoreUnexpectedFloorChanges: %ld", navigationRequest.timeToIgnoreUnexpectedFloorChanges]);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
_navigationUpdates = YES;
|
|
669
|
+
[[SITNavigationManager sharedManager] setDelegate:self]; // Configure delegation first
|
|
670
|
+
[[SITNavigationManager sharedManager] requestNavigationUpdates:navigationRequest];
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
RCT_EXPORT_METHOD(updateNavigationWithLocation:(NSDictionary *)location withSuccessCallback:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock)
|
|
677
|
+
{
|
|
678
|
+
@try {
|
|
679
|
+
[[SITNavigationManager sharedManager] updateWithLocation:[SitumLocationWrapper.shared locationJsonObjectToLocation:location]];
|
|
680
|
+
|
|
681
|
+
successBlock(@[@"Navigation updated"]);
|
|
682
|
+
}
|
|
683
|
+
@catch (NSException *exception) {
|
|
684
|
+
if(errorBlock){
|
|
685
|
+
errorBlock(@[exception.reason]);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
RCT_EXPORT_METHOD(removeNavigationUpdates:(RCTResponseSenderBlock)callbackBlock)
|
|
691
|
+
{
|
|
692
|
+
_navigationUpdates = NO;
|
|
693
|
+
[[SITNavigationManager sharedManager] removeUpdates];
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
RCT_EXPORT_METHOD(requestRealTimeUpdates:(NSDictionary *)realtimeRequest)
|
|
697
|
+
{
|
|
698
|
+
SITRealTimeRequest *request = [SitumLocationWrapper.shared realtimeRequestFromJson:realtimeRequest];
|
|
699
|
+
|
|
700
|
+
_realtimeUpdates = YES;
|
|
701
|
+
|
|
702
|
+
[[SITRealTimeManager sharedManager] requestRealTimeUpdates:request];
|
|
703
|
+
[SITRealTimeManager sharedManager].delegate = self;
|
|
704
|
+
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
RCT_EXPORT_METHOD(removeRealTimeUpdates)
|
|
708
|
+
{
|
|
709
|
+
NSLog(@"REMOVING UPDATESSSS");
|
|
710
|
+
_realtimeUpdates = NO;
|
|
711
|
+
[[SITRealTimeManager sharedManager] removeRealTimeUpdates];
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
RCT_EXPORT_METHOD(invalidateCache)
|
|
715
|
+
{
|
|
716
|
+
NSMutableDictionary *obj = [[NSMutableDictionary alloc] init];
|
|
717
|
+
[[SITCommunicationManager sharedManager] clearCache];
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
RCT_EXPORT_METHOD(requestAuthorization){
|
|
721
|
+
if (!_locationManager) {
|
|
722
|
+
_locationManager = [CLLocationManager new];
|
|
723
|
+
_locationManager.delegate = self;
|
|
724
|
+
}
|
|
725
|
+
BOOL wantsAlways = NO;
|
|
726
|
+
BOOL wantsWhenInUse = NO;
|
|
727
|
+
if (_locationConfiguration.authorizationLevel == RNCSitumAuthorizationLevelDefault) {
|
|
728
|
+
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] &&
|
|
729
|
+
[_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
|
|
730
|
+
wantsAlways = YES;
|
|
731
|
+
} else if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] &&
|
|
732
|
+
[_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
|
|
733
|
+
wantsWhenInUse = YES;
|
|
734
|
+
}
|
|
735
|
+
} else if (_locationConfiguration.authorizationLevel == RNCSitumAuthorizationLevelAlways) {
|
|
736
|
+
wantsAlways = YES;
|
|
737
|
+
} else if (_locationConfiguration.authorizationLevel == RNCSitumAuthorizationLevelWhenInUse) {
|
|
738
|
+
wantsWhenInUse = YES;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// Request location access permission
|
|
742
|
+
if (wantsAlways) {
|
|
743
|
+
[_locationManager requestAlwaysAuthorization];
|
|
744
|
+
|
|
745
|
+
// On iOS 9+ we also need to enable background updates
|
|
746
|
+
NSArray *backgroundModes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIBackgroundModes"];
|
|
747
|
+
if (backgroundModes && [backgroundModes containsObject:@"location"]) {
|
|
748
|
+
if ([_locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
|
|
749
|
+
[_locationManager setAllowsBackgroundLocationUpdates:YES];
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
} else if (wantsWhenInUse) {
|
|
753
|
+
[_locationManager requestWhenInUseAuthorization];
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
RCT_EXPORT_METHOD(getDeviceId:(RCTResponseSenderBlock)callbackBlock)
|
|
758
|
+
{
|
|
759
|
+
callbackBlock(@[@{@"deviceId": SITServices.deviceID}]);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
RCT_EXPORT_METHOD(onEnterGeofences) {
|
|
763
|
+
[self attachGeofenceListener];
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
RCT_EXPORT_METHOD(onExitGeofences){
|
|
767
|
+
[self attachGeofenceListener];
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
- (void)attachGeofenceListener {
|
|
771
|
+
SITLocationManager.sharedInstance.geofenceDelegate = self;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// SITRealtimeDelegate methods
|
|
775
|
+
- (void)realTimeManager:(id <SITRealTimeInterface> _Nonnull)realTimeManager
|
|
776
|
+
didUpdateUserLocations:(SITRealTimeData * _Nonnull)realTimeData
|
|
777
|
+
{
|
|
778
|
+
// SITRealTimeData to json
|
|
779
|
+
NSDictionary *realtimeInfo = [SitumLocationWrapper.shared jsonFromRealtimeData:realTimeData];
|
|
780
|
+
NSLog(@"ADDDDDED UPDATESSSS");
|
|
781
|
+
if (_realtimeUpdates) {
|
|
782
|
+
[self sendEventWithName:@"realtimeUpdated" body:realtimeInfo.copy];
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
- (void)realTimeManager:(id <SITRealTimeInterface> _Nonnull)realTimeManager
|
|
787
|
+
didFailWithError:(NSError * _Nonnull)error
|
|
788
|
+
{
|
|
789
|
+
if (_realtimeUpdates) {
|
|
790
|
+
[self sendEventWithName:@"realtimeError" body:error.description];
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// SITLocationDelegate methods
|
|
795
|
+
|
|
796
|
+
- (void)locationManager:(nonnull id<SITLocationInterface>)locationManager
|
|
797
|
+
didUpdateLocation:(nonnull SITLocation *)location {
|
|
798
|
+
if (location) {
|
|
799
|
+
NSDictionary *locationJO = [SitumLocationWrapper.shared locationToJsonObject:location];
|
|
800
|
+
|
|
801
|
+
if (_positioningUpdates) {
|
|
802
|
+
[self sendEventWithName:@"locationChanged" body:locationJO];
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
- (void)locationManager:(nonnull id<SITLocationInterface>)locationManager
|
|
808
|
+
didFailWithError: (NSError * _Nullable)error {
|
|
809
|
+
|
|
810
|
+
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
|
811
|
+
[dict setObject:error.description forKey:@"message"];
|
|
812
|
+
|
|
813
|
+
if (_positioningUpdates) {
|
|
814
|
+
[self sendEventWithName:@"locationError" body:error.description];
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
- (void)locationManager:(nonnull id<SITLocationInterface>)locationManager
|
|
819
|
+
didUpdateState:(SITLocationState)state {
|
|
820
|
+
|
|
821
|
+
NSDictionary *locationChanged = [SitumLocationWrapper.shared locationStateToJsonObject:state];
|
|
822
|
+
if (_positioningUpdates) {
|
|
823
|
+
[self sendEventWithName:@"statusChanged" body:locationChanged.copy];
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// SITDirectionsDelegate
|
|
828
|
+
|
|
829
|
+
- (void)directionsManager:(id<SITDirectionsInterface>)manager
|
|
830
|
+
didFailProcessingRequest:(SITDirectionsRequest *)request
|
|
831
|
+
withError:(NSError *)error {
|
|
832
|
+
|
|
833
|
+
self.computedRoute = nil; // if something fails then the previous computedRoute is clean
|
|
834
|
+
|
|
835
|
+
// if(directionRequest.errorBlock){
|
|
836
|
+
routeRequest.errorBlock(@[error.description]);
|
|
837
|
+
// }
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
- (void)directionsManager:(id<SITDirectionsInterface>)manager
|
|
841
|
+
didProcessRequest:(SITDirectionsRequest *)request
|
|
842
|
+
withResponse:(SITRoute *)route {
|
|
843
|
+
|
|
844
|
+
NSString * timestamp = [NSString stringWithFormat:@"%f",[[NSDate date] timeIntervalSince1970] * 1000];
|
|
845
|
+
|
|
846
|
+
NSMutableDictionary *routeJO = [[SitumLocationWrapper.shared routeToJsonObject:route] mutableCopy];
|
|
847
|
+
[routesStored setObject:route forKey:timestamp];
|
|
848
|
+
|
|
849
|
+
self.computedRoute = route; // We store the computed route in order to insert it into the navigation component if neccessary
|
|
850
|
+
|
|
851
|
+
routeRequest.successBlock(@[routeJO.copy]);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// SITNavigationDelegate
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
- (void)navigationManager:(id<SITNavigationInterface>)navigationManager
|
|
858
|
+
didFailWithError:(NSError *)error {
|
|
859
|
+
if (_navigationUpdates) {
|
|
860
|
+
[self sendEventWithName:@"navigationError" body:error.description];
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
- (void)navigationManager:(id<SITNavigationInterface>)navigationManager
|
|
865
|
+
didUpdateProgress:(SITNavigationProgress *)progress
|
|
866
|
+
onRoute:(SITRoute *)route {
|
|
867
|
+
NSMutableDictionary *navigationJO = [NSMutableDictionary dictionaryWithDictionary:[SitumLocationWrapper.shared navigationProgressToJsonObject:progress]];
|
|
868
|
+
[navigationJO setValue:@"progress" forKey:@"type"];
|
|
869
|
+
|
|
870
|
+
if (_navigationUpdates) {
|
|
871
|
+
[self sendEventWithName:@"navigationUpdated" body:navigationJO.copy];
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
- (void)navigationManager:(id<SITNavigationInterface>)navigationManager
|
|
876
|
+
destinationReachedOnRoute:(SITRoute *)route {
|
|
877
|
+
NSMutableDictionary *navigationJO = [[NSMutableDictionary alloc] init];
|
|
878
|
+
[navigationJO setValue:@"destinationReached" forKey:@"type"];
|
|
879
|
+
[navigationJO setValue:@"Destination reached" forKey:@"message"];
|
|
880
|
+
|
|
881
|
+
if (_navigationUpdates) {
|
|
882
|
+
[self sendEventWithName:@"navigationUpdated" body:navigationJO.copy];
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
- (void)navigationManager:(id<SITNavigationInterface>)navigationManager
|
|
888
|
+
userOutsideRoute:(SITRoute *)route {
|
|
889
|
+
NSMutableDictionary *navigationJO = [[NSMutableDictionary alloc] init];
|
|
890
|
+
[navigationJO setValue:@"userOutsideRoute" forKey:@"type"];
|
|
891
|
+
[navigationJO setValue:@"User outside route" forKey:@"message"];
|
|
892
|
+
|
|
893
|
+
if (_navigationUpdates) {
|
|
894
|
+
[self sendEventWithName:@"navigationUpdated" body:navigationJO.copy];
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
- (void)didEnteredGeofences:(NSArray<SITGeofence *> *)geofences {
|
|
900
|
+
NSArray *geofencesJO = [SitumLocationWrapper.shared geofencesToJsonArray:geofences];
|
|
901
|
+
|
|
902
|
+
[self sendEventWithName:@"onEnterGeofences" body:geofencesJO];
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
- (void)didExitedGeofences:(NSArray<SITGeofence *> *)geofences {
|
|
906
|
+
|
|
907
|
+
NSArray *geofencesJO = [SitumLocationWrapper.shared geofencesToJsonArray:geofences];
|
|
908
|
+
|
|
909
|
+
[self sendEventWithName:@"onExitGeofences" body:geofencesJO];
|
|
910
|
+
}
|
|
911
|
+
@end
|