react-native-mapp-plugin 1.4.2 → 2.0.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.
@@ -11,8 +11,6 @@ import android.content.Intent;
11
11
  import android.content.pm.PackageManager;
12
12
  import android.net.Uri;
13
13
  import android.os.Build;
14
- import android.os.Handler;
15
- import android.os.Looper;
16
14
  import android.util.DisplayMetrics;
17
15
  import android.provider.Settings;
18
16
 
@@ -24,6 +22,7 @@ import androidx.core.content.ContextCompat;
24
22
  import com.appoxee.Appoxee;
25
23
  import com.appoxee.internal.model.response.DevicePayload;
26
24
  import com.appoxee.shared.InboxMessage;
25
+ import com.appoxee.shared.MessageStatus;
27
26
  import com.appoxee.sdk.BuildConfig;
28
27
  import com.appoxee.shared.AppoxeeObserver;
29
28
  import com.appoxee.shared.AppoxeeOptions;
@@ -80,12 +79,15 @@ public class RNMappPluginModule extends NativeRNMappPluginModuleSpec implements
80
79
 
81
80
  public static final String NAME = "RNMappPluginModule";
82
81
  private static final int POST_NOTIFICATION_PERMISSION_REQUEST_CODE = 1001;
82
+ private static final int GEOFENCE_PERMISSION_REQUEST_CODE = 2001;
83
83
  private final ReactApplicationContext reactContext;
84
84
  private Map<Callback, String> mFeedSubscriberMap = new ConcurrentHashMap<>();
85
85
  private Map<Callback, Boolean> mCallbackWasCalledMap = new ConcurrentHashMap<>();
86
86
  private final Map<Integer, Promise> notificationPermissionPromises = new ConcurrentHashMap<>();
87
+ private final Map<Integer, Promise> geofencePermissionPromises = new ConcurrentHashMap<>();
87
88
  private Application application = null;
88
89
  private int nextNotificationPermissionRequestCode = POST_NOTIFICATION_PERMISSION_REQUEST_CODE;
90
+ private int nextGeofencePermissionRequestCode = GEOFENCE_PERMISSION_REQUEST_CODE;
89
91
 
90
92
  public RNMappPluginModule(ReactApplicationContext reactContext) {
91
93
  super(reactContext);
@@ -128,10 +130,32 @@ public class RNMappPluginModule extends NativeRNMappPluginModuleSpec implements
128
130
  promise.resolve(true);
129
131
  return;
130
132
  }
131
- int fineLocation = ContextCompat.checkSelfPermission(reactContext, Manifest.permission.ACCESS_FINE_LOCATION);
132
- int backgroundLocation = ContextCompat.checkSelfPermission(reactContext, Manifest.permission.ACCESS_BACKGROUND_LOCATION);
133
- promise.resolve(fineLocation == PackageManager.PERMISSION_GRANTED
134
- && backgroundLocation == PackageManager.PERMISSION_GRANTED);
133
+ if (hasFineLocationPermission() && hasBackgroundLocationPermission()) {
134
+ promise.resolve(true);
135
+ return;
136
+ }
137
+ Activity activity = getCurrentActivity();
138
+ if (!(activity instanceof PermissionAwareActivity)) {
139
+ promise.resolve(false);
140
+ return;
141
+ }
142
+ int requestCode = nextGeofencePermissionRequestCode++;
143
+ geofencePermissionPromises.put(requestCode, promise);
144
+ String[] permissions = hasFineLocationPermission()
145
+ ? new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION}
146
+ : new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
147
+ ((PermissionAwareActivity) activity).requestPermissions(permissions, requestCode, this);
148
+ }
149
+
150
+ private boolean hasFineLocationPermission() {
151
+ return ContextCompat.checkSelfPermission(reactContext, Manifest.permission.ACCESS_FINE_LOCATION)
152
+ == PackageManager.PERMISSION_GRANTED;
153
+ }
154
+
155
+ private boolean hasBackgroundLocationPermission() {
156
+ return Build.VERSION.SDK_INT < Build.VERSION_CODES.Q
157
+ || ContextCompat.checkSelfPermission(reactContext, Manifest.permission.ACCESS_BACKGROUND_LOCATION)
158
+ == PackageManager.PERMISSION_GRANTED;
135
159
  }
136
160
 
137
161
  @ReactMethod
@@ -168,6 +192,31 @@ public class RNMappPluginModule extends NativeRNMappPluginModuleSpec implements
168
192
 
169
193
  @Override
170
194
  public boolean onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
195
+ Promise geofencePromise = geofencePermissionPromises.remove(requestCode);
196
+ if (geofencePromise != null) {
197
+ boolean granted = grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
198
+ if (!granted) {
199
+ geofencePromise.resolve(false);
200
+ return true;
201
+ }
202
+ if (!hasBackgroundLocationPermission()) {
203
+ Activity activity = getCurrentActivity();
204
+ if (!(activity instanceof PermissionAwareActivity)) {
205
+ geofencePromise.resolve(false);
206
+ return true;
207
+ }
208
+ int backgroundRequestCode = nextGeofencePermissionRequestCode++;
209
+ geofencePermissionPromises.put(backgroundRequestCode, geofencePromise);
210
+ ((PermissionAwareActivity) activity).requestPermissions(
211
+ new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION},
212
+ backgroundRequestCode,
213
+ this
214
+ );
215
+ return true;
216
+ }
217
+ geofencePromise.resolve(hasFineLocationPermission());
218
+ return true;
219
+ }
171
220
  Promise promise = notificationPermissionPromises.remove(requestCode);
172
221
  if (promise == null) {
173
222
  return false;
@@ -287,11 +336,24 @@ public class RNMappPluginModule extends NativeRNMappPluginModuleSpec implements
287
336
  FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener<String>() {
288
337
  @Override
289
338
  public void onComplete(@NonNull Task<String> task) {
290
- promise.resolve(task.getResult());
339
+ settleTokenTask(task, promise);
291
340
  }
292
341
  });
293
342
  }
294
343
 
344
+ static void settleTokenTask(@NonNull Task<String> task, @NonNull Promise promise) {
345
+ if (task.isSuccessful()) {
346
+ promise.resolve(task.getResult());
347
+ return;
348
+ }
349
+
350
+ Exception exception = task.getException();
351
+ String message = exception != null && exception.getMessage() != null
352
+ ? exception.getMessage()
353
+ : "FCM registration failed";
354
+ promise.reject("FCM_REGISTRATION_FAILED", message, exception);
355
+ }
356
+
295
357
  // -------------------------------------------------------------------------
296
358
  // Alias
297
359
  // -------------------------------------------------------------------------
@@ -318,7 +380,7 @@ public class RNMappPluginModule extends NativeRNMappPluginModuleSpec implements
318
380
  @ReactMethod
319
381
  @Deprecated(forRemoval = true)
320
382
  public void engage2() {
321
- Appoxee.engage(application,null);
383
+ MappEngagementDispatcher.engageAsync(Objects.requireNonNull(application), null, null);
322
384
  }
323
385
 
324
386
  @ReactMethod
@@ -326,9 +388,7 @@ public class RNMappPluginModule extends NativeRNMappPluginModuleSpec implements
326
388
  AppoxeeOptions opt = createOptions(server, sdkKey, appID, tenantID);
327
389
  opt.setNotificationMode(NotificationMode.BACKGROUND_AND_FOREGROUND);
328
390
 
329
- new Handler(Looper.getMainLooper()).post(() -> {
330
- Appoxee.engage(Objects.requireNonNull(application), opt);
331
-
391
+ MappEngagementDispatcher.engageAsync(Objects.requireNonNull(application), opt, () -> {
332
392
  Appoxee.instance().subscribe(new AppoxeeObserver() {
333
393
  @Override
334
394
  public void onReadyStatusChanged(boolean status, MappResult<DevicePayload> result) {
@@ -344,9 +404,7 @@ public class RNMappPluginModule extends NativeRNMappPluginModuleSpec implements
344
404
  String appID, String tenantID) {
345
405
  AppoxeeOptions opt = createOptions(server, sdkKey, appID, tenantID);
346
406
 
347
- new Handler(Looper.getMainLooper()).post(() -> {
348
- Appoxee.engage(Objects.requireNonNull(application), opt);
349
-
407
+ MappEngagementDispatcher.engageAsync(Objects.requireNonNull(application), opt, () -> {
350
408
  Appoxee.instance().subscribe(new AppoxeeObserver() {
351
409
  @Override
352
410
  public void onReadyStatusChanged(boolean status, MappResult<DevicePayload> result) {
@@ -738,33 +796,41 @@ public class RNMappPluginModule extends NativeRNMappPluginModuleSpec implements
738
796
  });
739
797
  }
740
798
 
741
- /**
742
- * Stubbed: InApp statistics internal classes were removed in v7.
743
- * The @ReactMethod signature is preserved to avoid breaking the JS public API.
744
- */
745
799
  @ReactMethod
746
800
  public void inAppMarkAsRead(double templateId, String eventId) {
747
- // no-op in v7
801
+ updateInboxMessageStatus((long) templateId, MessageStatus.READ);
748
802
  }
749
803
 
750
- /**
751
- * @see #inAppMarkAsRead
752
- */
753
804
  @ReactMethod
754
805
  public void inAppMarkAsUnRead(double templateId, String eventId) {
755
- // no-op in v7
806
+ updateInboxMessageStatus((long) templateId, MessageStatus.UNREAD);
756
807
  }
757
808
 
758
- /**
759
- * @see #inAppMarkAsRead
760
- */
761
809
  @ReactMethod
762
810
  public void inAppMarkAsDeleted(double templateId, String eventId) {
763
- // no-op in v7
811
+ updateInboxMessageStatus((long) templateId, MessageStatus.DELETED);
764
812
  }
765
813
 
766
814
  /**
767
- * @see #inAppMarkAsRead
815
+ * Mapp Engage v7 updates inbox state using the SDK's InboxMessage object,
816
+ * so fetch the message by template ID before sending the status update.
817
+ * The legacy eventId argument is not required by the v7 API.
818
+ */
819
+ private void updateInboxMessageStatus(long templateId, MessageStatus status) {
820
+ final Appoxee appoxee = Appoxee.instance();
821
+ appoxee.fetchInboxMessage(templateId).enqueue(fetchResult -> {
822
+ if (fetchResult == null || !fetchResult.isSuccess() || fetchResult.getData() == null) {
823
+ return;
824
+ }
825
+
826
+ appoxee.updateInboxMessageStatus(fetchResult.getData(), status).enqueue(updateResult -> {
827
+ });
828
+ });
829
+ }
830
+
831
+ /**
832
+ * Stubbed: InApp statistics internal classes were removed in v7.
833
+ * The @ReactMethod signature is preserved to avoid breaking the JS public API.
768
834
  */
769
835
  @ReactMethod
770
836
  public void triggerStatistic(double templateId, String originalEventId,
package/app.plugin.js ADDED
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ module.exports = require('./plugin/build').withMappEngage;
4
+
@@ -43,6 +43,11 @@ NSString *const MappRNInappMessage = @"com.mapp.inapp_message";
43
43
 
44
44
  -(void)startObserving {
45
45
  hasListeners = YES;
46
+ NSArray *events = [self.pendingEvents copy];
47
+ [self.pendingEvents removeAllObjects];
48
+ for (NSDictionary *event in events) {
49
+ [super sendEventWithName:event[@"name"] body:event[@"body"]];
50
+ }
46
51
  }
47
52
 
48
53
  -(void)stopObserving {
@@ -50,7 +55,22 @@ NSString *const MappRNInappMessage = @"com.mapp.inapp_message";
50
55
  }
51
56
 
52
57
  - (NSArray<NSString *> *)supportedEvents {
53
- return @[MappRNInitEvent, MappRNInboxMessageReceived, MappRNInboxMessagesReceived, MappRNLocationEnter, MappRNCustomLinkReceived, MappRNDeepLinkReceived, MappRNRichMessage,MappRNPushMessage, MappErrorMessage,MappRNInappMessage];
58
+ return @[MappRNInitEvent, MappRNInboxMessageReceived, MappRNInboxMessagesReceived, MappRNLocationEnter, MappRNLocationExit, MappRNCustomLinkReceived, MappRNDeepLinkReceived, MappRNRichMessage,MappRNPushMessage, MappErrorMessage,MappRNInappMessage];
59
+ }
60
+
61
+ - (void)sendEventWithName:(NSString *)name body:(id)body {
62
+ if (hasListeners) {
63
+ [super sendEventWithName:name body:body];
64
+ return;
65
+ }
66
+ if (!self.pendingEvents) {
67
+ self.pendingEvents = [NSMutableArray array];
68
+ }
69
+ // Bound the cold-start queue so repeated background callbacks cannot grow it forever.
70
+ if (self.pendingEvents.count >= 50) {
71
+ [self.pendingEvents removeObjectAtIndex:0];
72
+ }
73
+ [self.pendingEvents addObject:@{ @"name": name, @"body": body ?: [NSNull null] }];
54
74
  }
55
75
 
56
76
  - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
@@ -224,4 +244,3 @@ NSString *const MappRNInappMessage = @"com.mapp.inapp_message";
224
244
  }
225
245
  @end
226
246
 
227
-
@@ -4,7 +4,26 @@
4
4
  #import "AppoxeeInapp.h"
5
5
  #import "AppoxeeLocationManager.h"
6
6
  #import <UserNotifications/UNUserNotificationCenter.h>
7
+ #if RCT_NEW_ARCH_ENABLED
8
+ #import <ReactCommon/RCTTurboModule.h>
9
+ #if __has_include(<RNMappPluginSpec/RNMappPluginSpec.h>)
10
+ #import <RNMappPluginSpec/RNMappPluginSpec.h>
11
+ #define RNMAPP_HAS_TURBO_MODULE_SPEC 1
12
+ #elif __has_include(<RNMappPlugin/RNMappPlugin.h>)
13
+ #import <RNMappPlugin/RNMappPlugin.h>
14
+ #define RNMAPP_HAS_TURBO_MODULE_SPEC 1
15
+ #elif __has_include("RNMappPlugin.h")
16
+ #import "RNMappPlugin.h"
17
+ #define RNMAPP_HAS_TURBO_MODULE_SPEC 1
18
+ #else
19
+ #define RNMAPP_HAS_TURBO_MODULE_SPEC 0
20
+ #endif
21
+ #endif
7
22
 
8
- @interface RNMappPluginModule : NSObject <RCTBridgeModule,AppoxeeInappDelegate, AppoxeeNotificationDelegate, AppoxeeLocationManagerDelegate >
23
+ @interface RNMappPluginModule : NSObject <RCTBridgeModule,AppoxeeInappDelegate, AppoxeeNotificationDelegate, AppoxeeLocationManagerDelegate
24
+ #if RCT_NEW_ARCH_ENABLED && RNMAPP_HAS_TURBO_MODULE_SPEC
25
+ , NativeRNMappPluginModuleSpec
26
+ #endif
27
+ >
9
28
 
10
29
  @end
@@ -1,9 +1,32 @@
1
1
  #import "RNMappPluginModule.h"
2
2
  #import "RNMappEventEmmiter.h"
3
+ #if RCT_NEW_ARCH_ENABLED
4
+ #import <ReactCommon/RCTTurboModule.h>
5
+ #if __has_include(<RNMappPluginSpec/RNMappPluginSpec.h>)
6
+ #import <RNMappPluginSpec/RNMappPluginSpec.h>
7
+ #define RNMAPP_HAS_TURBO_MODULE_SPEC 1
8
+ #elif __has_include(<RNMappPlugin/RNMappPlugin.h>)
9
+ #import <RNMappPlugin/RNMappPlugin.h>
10
+ #define RNMAPP_HAS_TURBO_MODULE_SPEC 1
11
+ #elif __has_include("RNMappPlugin.h")
12
+ #import "RNMappPlugin.h"
13
+ #define RNMAPP_HAS_TURBO_MODULE_SPEC 1
14
+ #else
15
+ #define RNMAPP_HAS_TURBO_MODULE_SPEC 0
16
+ #endif
17
+ #endif
3
18
 
4
19
 
5
20
  @implementation RNMappPluginModule
6
21
 
22
+ #if RCT_NEW_ARCH_ENABLED && RNMAPP_HAS_TURBO_MODULE_SPEC
23
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
24
+ (const facebook::react::ObjCTurboModule::InitParams &)params
25
+ {
26
+ return std::make_shared<facebook::react::NativeRNMappPluginModuleSpecJSI>(params);
27
+ }
28
+ #endif
29
+
7
30
 
8
31
  - (void)setBridge:(RCTBridge *)bridge {
9
32
  [RNMappEventEmmiter shared].bridge = bridge;
@@ -35,20 +58,87 @@ RCT_EXPORT_METHOD(removeListeners:(NSInteger)count) {
35
58
  [[RNMappEventEmmiter shared] removeListeners:count];
36
59
  }
37
60
 
38
- #pragma mark Exported methods - Notifications
61
+ // Cross-platform TurboModule methods that need iOS-specific behavior or have no
62
+ // meaningful iOS equivalent. Keeping them here makes the generated spec safe to
63
+ // invoke under the New Architecture instead of relying on legacy interop.
64
+ RCT_EXPORT_METHOD(requestGeofenceLocationPermission:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
65
+ CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
66
+ if (status == kCLAuthorizationStatusNotDetermined) {
67
+ [[[CLLocationManager alloc] init] requestAlwaysAuthorization];
68
+ }
69
+ resolve(@(status == kCLAuthorizationStatusAuthorizedAlways));
70
+ }
71
+
72
+ RCT_EXPORT_METHOD(requestPostNotificationPermission:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
73
+ [[UNUserNotificationCenter currentNotificationCenter]
74
+ requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound)
75
+ completionHandler:^(BOOL granted, NSError *error) {
76
+ if (error) reject(@"NOTIFICATION_PERMISSION_ERROR", @"Unable to request notification permission", error);
77
+ else resolve(@(granted));
78
+ }];
79
+ }
80
+
81
+ RCT_EXPORT_METHOD(setRemoteMessage:(NSString *)msgJson resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
82
+ // iOS delivery is handled by APNs/Appoxee auto-integration, not FCM RemoteMessage JSON.
83
+ resolve(@NO);
84
+ }
85
+
86
+ RCT_EXPORT_METHOD(isPushFromMapp:(NSString *)msgJson resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
87
+ resolve(@NO);
88
+ }
39
89
 
40
- RCT_EXPORT_METHOD(engage: (NSString *)sdkKey projectId: (NSString *)projectId cepUrl:(NSString *)cepUrl appID:(NSString *)appID tenantID:(NSString *)tenantID) {
41
- SERVER serv = [self getServerKeyFor:cepUrl];
42
- [[Appoxee shared] engageWithLaunchOptions:nil andDelegate:[RNMappEventEmmiter shared] andSDKID:sdkKey with: serv];
90
+ RCT_EXPORT_METHOD(getToken:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
91
+ reject(@"APNS_TOKEN_UNAVAILABLE", @"Mapp auto-integration owns the native APNs token on iOS", nil);
43
92
  }
44
93
 
45
- RCT_REMAP_METHOD(autoengage,engage:(NSString *) server) {
94
+ RCT_EXPORT_METHOD(engage2) {}
95
+
96
+ RCT_EXPORT_METHOD(engageTestServer:(NSString *)cepUrl sdkKey:(NSString *)sdkKey googleProjectId:(NSString *)projectId server:(NSString *)server appID:(NSString *)appID tenantID:(NSString *)tenantID) {
97
+ [self engage:sdkKey googleProjectId:projectId server:server appID:appID tenantID:tenantID];
98
+ }
99
+
100
+ RCT_EXPORT_METHOD(onInitCompletedListener:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
101
+ resolve(@([[Appoxee shared] isReady]));
102
+ }
103
+
104
+ RCT_EXPORT_METHOD(setAttributeBoolean:(NSString *)key value:(BOOL)value) {
105
+ [[Appoxee shared] setNumberValue:@(value) forKey:key withCompletionHandler:nil];
106
+ }
107
+
108
+ RCT_EXPORT_METHOD(removeAttribute:(NSString *)attribute) {
109
+ // The vendored iOS SDK has no single-field removal API.
110
+ }
111
+
112
+ RCT_EXPORT_METHOD(getDeviceDmcInfo:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
113
+ [self getDeviceInfo:resolve reject:reject];
114
+ }
115
+
116
+ RCT_EXPORT_METHOD(lockScreenOrientation:(NSInteger)orientation) {}
117
+
118
+ RCT_EXPORT_METHOD(startGeofencing:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
119
+ [[AppoxeeLocationManager shared] enableLocationMonitoring];
120
+ resolve(@"started");
121
+ }
122
+
123
+ RCT_EXPORT_METHOD(stopGeofencing:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
124
+ [[AppoxeeLocationManager shared] disableLocationMonitoring];
125
+ resolve(@"stopped");
126
+ }
127
+
128
+ RCT_EXPORT_METHOD(triggerStatistic:(NSInteger)templateId originalEventId:(NSString *)originalEventId trackingKey:(NSString *)trackingKey displayMillis:(NSInteger)displayMillis reason:(NSString *)reason link:(NSString *)link) {}
129
+ RCT_EXPORT_METHOD(addAndroidListener:(NSString *)eventName) {}
130
+ RCT_EXPORT_METHOD(removeAndroidListeners:(NSInteger)count) {}
131
+
132
+ #pragma mark Exported methods - Notifications
133
+
134
+ RCT_EXPORT_METHOD(engage: (NSString *)sdkKey googleProjectId: (NSString *)projectId server:(NSString *)server appID:(NSString *)appID tenantID:(NSString *)tenantID) {
46
135
  SERVER serv = [self getServerKeyFor:server];
47
136
  [[Appoxee shared] engageAndAutoIntegrateWithLaunchOptions:nil andDelegate:[RNMappEventEmmiter shared] with:serv];
48
137
  [[Appoxee shared] addObserver: [RNMappEventEmmiter shared] forKeyPath:@"isReady" options:NSKeyValueObservingOptionNew context:nil];
138
+ [[AppoxeeInapp shared] engageWithDelegate:[RNMappEventEmmiter shared] with:[self getInappServerKeyFor:server]];
49
139
  }
50
140
 
51
- RCT_EXPORT_METHOD(getAlias:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
141
+ RCT_EXPORT_METHOD(getAlias:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
52
142
  [[Appoxee shared] getDeviceAliasWithCompletionHandler:^(NSError * _Nullable appoxeeError, id _Nullable data) {
53
143
  if (appoxeeError == nil && data != nil) {
54
144
  resolve(data);
@@ -58,24 +148,34 @@ RCT_EXPORT_METHOD(getAlias:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseR
58
148
  }];
59
149
  }
60
150
 
61
- RCT_EXPORT_METHOD(setAlias:(NSString *) alias) {
151
+ RCT_EXPORT_METHOD(setAlias:(NSString *) alias resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
62
152
  [[Appoxee shared] setDeviceAlias:alias withCompletionHandler:^(NSError * _Nullable appoxeeError, id _Nullable data) {
63
153
  if (appoxeeError != nil) {
64
- NSLog(@"%@", appoxeeError.debugDescription);
154
+ reject(@"SET_ALIAS_ERROR", @"Failed to set alias", appoxeeError);
155
+ } else {
156
+ resolve(@YES);
65
157
  }
66
158
  }];
67
159
  }
68
160
 
69
- RCT_EXPORT_METHOD(setAliasWithResend:(NSString *) alias withResendAttributes:(BOOL) resendAttributes) {
161
+ RCT_EXPORT_METHOD(setAliasWithResend:(NSString *) alias resendCustomAttributes:(BOOL) resendAttributes resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
70
162
  [[Appoxee shared] setDeviceAlias:alias withResendAttributes:resendAttributes withCompletionHandler:^(NSError * _Nullable appoxeeError, id _Nullable data) {
71
163
  if (appoxeeError != nil) {
72
- NSLog(@"%@", appoxeeError.debugDescription);
164
+ reject(@"SET_ALIAS_ERROR", @"Failed to set alias", appoxeeError);
165
+ } else {
166
+ resolve(@YES);
73
167
  }
74
168
  }];
75
169
  }
76
170
 
77
- RCT_EXPORT_METHOD(setToken:(NSString *) token) {
78
- [[Appoxee shared] didRegisterForRemoteNotificationsWithDeviceToken:[[NSData alloc] initWithBase64EncodedString:token options:NSUTF8StringEncoding]];
171
+ RCT_EXPORT_METHOD(setToken:(NSString *) token resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
172
+ NSData *deviceToken = [[NSData alloc] initWithBase64EncodedString:token options:0];
173
+ if (!deviceToken) {
174
+ reject(@"INVALID_APNS_TOKEN", @"setToken expects a base64-encoded native APNs device token, not an Expo push token", nil);
175
+ return;
176
+ }
177
+ [[Appoxee shared] didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
178
+ resolve(@YES);
79
179
  }
80
180
 
81
181
  RCT_EXPORT_METHOD(removeDeviceAlias) {
@@ -90,11 +190,11 @@ RCT_EXPORT_METHOD(logOut: (BOOL) pushEnabled) {
90
190
  [[Appoxee shared] logoutWithOptin:pushEnabled];
91
191
  }
92
192
 
93
- RCT_EXPORT_METHOD(isReady:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
193
+ RCT_EXPORT_METHOD(isReady:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
94
194
  resolve(@([[Appoxee shared] isReady]));
95
195
  }
96
196
 
97
- RCT_EXPORT_METHOD(isPushEnabled:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
197
+ RCT_EXPORT_METHOD(isPushEnabled:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
98
198
  [[Appoxee shared] isPushEnabled:^(NSError * _Nullable appoxeeError, id _Nullable data) {
99
199
  if (appoxeeError == nil) {
100
200
  resolve(data);
@@ -132,15 +232,17 @@ RCT_EXPORT_METHOD(incrementNumericKey: (NSString *) key value: (NSNumber *) numb
132
232
  }];
133
233
  }
134
234
 
135
- RCT_EXPORT_METHOD(setAttributes: (NSDictionary *)attributes) {
235
+ RCT_EXPORT_METHOD(setAttributes: (NSDictionary *)attributes resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
136
236
  [[Appoxee shared] setCustomAttributtes:attributes withCompletionHandler:^(NSError * _Nullable appoxeeError, id _Nullable data) {
137
237
  if (appoxeeError) {
138
- NSLog(@"%@", appoxeeError.debugDescription);
238
+ reject(@"SET_ATTRIBUTES_ERROR", @"Failed to set attributes", appoxeeError);
239
+ } else {
240
+ resolve(@YES);
139
241
  }
140
242
  }];
141
243
  }
142
244
 
143
- RCT_EXPORT_METHOD(getAttributes: (NSArray *)attributes and:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
245
+ RCT_EXPORT_METHOD(getAttributes: (NSArray *)attributes resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
144
246
  [[Appoxee shared] getCustomAttributes:attributes withCompletionHandler:^(NSError * _Nullable appoxeeError, id _Nullable data) {
145
247
  if (appoxeeError) {
146
248
  NSLog(@"%@", appoxeeError.debugDescription);
@@ -157,8 +259,8 @@ RCT_EXPORT_METHOD(setAttribute: (NSString *)key value: (NSString *) value) {
157
259
  }];
158
260
  }
159
261
 
160
- RCT_EXPORT_METHOD(setAttributeInt: (NSString *)key value: (NSNumber *) value) {
161
- [[Appoxee shared] setNumberValue:value forKey:key withCompletionHandler:^(NSError * _Nullable appoxeeError, id _Nullable data) {
262
+ RCT_EXPORT_METHOD(setAttributeInt: (NSString *)key value: (NSInteger) value) {
263
+ [[Appoxee shared] setNumberValue:@(value) forKey:key withCompletionHandler:^(NSError * _Nullable appoxeeError, id _Nullable data) {
162
264
  if(appoxeeError != nil) {
163
265
  NSLog(@"%@", appoxeeError.debugDescription);
164
266
  }
@@ -181,7 +283,7 @@ RCT_EXPORT_METHOD(addTag: (NSString *) tag) {
181
283
  }];
182
284
  }
183
285
 
184
- RCT_EXPORT_METHOD(getTags:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
286
+ RCT_EXPORT_METHOD(getTags:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
185
287
  [[Appoxee shared] fetchDeviceTags:^(NSError * _Nullable appoxeeError, id _Nullable data) {
186
288
  if (!appoxeeError && [data isKindOfClass:[NSArray class]]) {
187
289
  NSArray *deviceTags = (NSArray *)data;
@@ -192,7 +294,7 @@ RCT_EXPORT_METHOD(getTags:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRe
192
294
  }];
193
295
  }
194
296
 
195
- RCT_EXPORT_METHOD(getDeviceInfo:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
297
+ RCT_EXPORT_METHOD(getDeviceInfo:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
196
298
  [[Appoxee shared] deviceInformationwithCompletionHandler:^(NSError * _Nullable appoxeeError, id _Nullable data) {
197
299
  if (!appoxeeError && [data isKindOfClass:[APXClientDevice class]]) {
198
300
  APXClientDevice *device = (APXClientDevice *)data;
@@ -204,7 +306,7 @@ RCT_EXPORT_METHOD(getDeviceInfo:(RCTPromiseResolveBlock)resolve rejecter:(RCTPro
204
306
  }];
205
307
  }
206
308
 
207
- RCT_EXPORT_METHOD(getAttributeStringValue: (NSString *) key resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
309
+ RCT_EXPORT_METHOD(getAttributeStringValue: (NSString *) key resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
208
310
  [[Appoxee shared] fetchCustomFieldByKey:key withCompletionHandler:^(NSError * _Nullable appoxeeError, id _Nullable data) {
209
311
  NSLog(@"%@", data);
210
312
  if (!appoxeeError && [data isKindOfClass:[NSDictionary class]]) {
@@ -245,23 +347,18 @@ RCT_EXPORT_METHOD(clearNotifications) {
245
347
  [[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
246
348
  }
247
349
 
248
- RCT_EXPORT_METHOD(clearNotification: (NSNumber *) index ){
249
- [[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers: @[[index stringValue]]];
350
+ RCT_EXPORT_METHOD(clearNotification: (NSInteger) index ){
351
+ [[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers: @[[NSString stringWithFormat:@"%ld", (long)index]]];
250
352
  }
251
353
 
252
354
  #pragma mark Exported methods - Inapp
253
355
 
254
- RCT_REMAP_METHOD(engageInapp,engageInapp:(NSString *) server) {
255
- INAPPSERVER serv = [self getInappServerKeyFor:server];
256
- [[AppoxeeInapp shared] engageWithDelegate:[RNMappEventEmmiter shared] with:serv];
257
- }
258
-
259
- RCT_EXPORT_METHOD(fetchInboxMessage: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
356
+ RCT_EXPORT_METHOD(fetchInboxMessage: (RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
260
357
  [[AppoxeeInapp shared] fetchAPXInBoxMessages];
261
358
  resolve(@"Fetching, set event listener for iOS");
262
359
  }
263
360
 
264
- RCT_EXPORT_METHOD(fetchLatestInboxMessage: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
361
+ RCT_EXPORT_METHOD(fetchLatestInboxMessage: (RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
265
362
  [[AppoxeeInapp shared] fetchAPXInBoxMessages];
266
363
  resolve(@"Fetching, set event listener for iOS");
267
364
  }
@@ -270,28 +367,28 @@ RCT_EXPORT_METHOD(triggerInApp: (NSString *) event) {
270
367
  [[AppoxeeInapp shared] reportInteractionEventWithName:event andAttributes:nil];
271
368
  }
272
369
 
273
- RCT_EXPORT_METHOD(inAppMarkAsRead: (NSNumber * _Nonnull) templateId event: (NSString * _Nonnull) eventId) {
274
- APXInBoxMessage *message = [[RNMappEventEmmiter shared] getMessageWith:templateId event:eventId];
370
+ RCT_EXPORT_METHOD(inAppMarkAsRead: (NSInteger) templateId eventId: (NSString * _Nonnull) eventId) {
371
+ APXInBoxMessage *message = [[RNMappEventEmmiter shared] getMessageWith:@(templateId) event:eventId];
275
372
  if (message) {
276
373
  [message markAsRead];
277
374
  }
278
375
  }
279
376
 
280
- RCT_EXPORT_METHOD(inAppMarkAsUnRead: (NSNumber * _Nonnull) templateId event: (NSString * _Nonnull) eventId) {
281
- APXInBoxMessage *message = [[RNMappEventEmmiter shared] getMessageWith:templateId event:eventId];
377
+ RCT_EXPORT_METHOD(inAppMarkAsUnRead: (NSInteger) templateId eventId: (NSString * _Nonnull) eventId) {
378
+ APXInBoxMessage *message = [[RNMappEventEmmiter shared] getMessageWith:@(templateId) event:eventId];
282
379
  if (message) {
283
380
  [message markAsUnread];
284
381
  }
285
382
  }
286
383
 
287
- RCT_EXPORT_METHOD(inAppMarkAsDeleted: (NSNumber * _Nonnull) templateId event: (NSString * _Nonnull) eventId) {
288
- APXInBoxMessage *message = [[RNMappEventEmmiter shared] getMessageWith:templateId event:eventId];
384
+ RCT_EXPORT_METHOD(inAppMarkAsDeleted: (NSInteger) templateId eventId: (NSString * _Nonnull) eventId) {
385
+ APXInBoxMessage *message = [[RNMappEventEmmiter shared] getMessageWith:@(templateId) event:eventId];
289
386
  if (message) {
290
387
  [message markAsDeleted];
291
388
  }
292
389
  }
293
390
 
294
- RCT_EXPORT_METHOD(isDeviceRegistered:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
391
+ RCT_EXPORT_METHOD(isDeviceRegistered:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
295
392
  resolve(@([[Appoxee shared] isReady]));
296
393
  }
297
394
 
@@ -371,4 +468,3 @@ RCT_EXPORT_METHOD(stopGeoFencing) {
371
468
 
372
469
 
373
470
  @end
374
-