|
18 | 18 | import com.facebook.react.bridge.WritableMap; |
19 | 19 | import com.facebook.react.modules.core.DeviceEventManagerModule; |
20 | 20 |
|
| 21 | +import com.iterable.iterableapi.AuthFailure; |
21 | 22 | import com.iterable.iterableapi.InboxSessionManager; |
22 | 23 | import com.iterable.iterableapi.IterableAction; |
23 | 24 | import com.iterable.iterableapi.IterableActionContext; |
24 | 25 | import com.iterable.iterableapi.IterableApi; |
25 | 26 | import com.iterable.iterableapi.IterableAuthHandler; |
| 27 | +import com.iterable.iterableapi.IterableAuthManager; |
26 | 28 | import com.iterable.iterableapi.IterableConfig; |
27 | 29 | import com.iterable.iterableapi.IterableCustomActionHandler; |
28 | 30 | import com.iterable.iterableapi.IterableAttributionInfo; |
@@ -87,7 +89,36 @@ public void initializeWithApiKey(String apiKey, ReadableMap configReadableMap, S |
87 | 89 | configBuilder.setAuthHandler(this); |
88 | 90 | } |
89 | 91 |
|
90 | | - IterableApi.initialize(reactContext, apiKey, configBuilder.build()); |
| 92 | + IterableConfig config = configBuilder.build(); |
| 93 | + IterableApi.initialize(reactContext, apiKey, config); |
| 94 | + |
| 95 | + // Update retry policy on existing authManager if it was already created |
| 96 | + // This fixes the issue where retryInterval is not respected after |
| 97 | + // re-initialization |
| 98 | + // TODO [SDK-197]: Fix the root cause of this issue, instead of this hack |
| 99 | + try { |
| 100 | + // Use reflection to access package-private fields and methods |
| 101 | + java.lang.reflect.Field configRetryPolicyField = config.getClass().getDeclaredField("retryPolicy"); |
| 102 | + configRetryPolicyField.setAccessible(true); |
| 103 | + Object retryPolicy = configRetryPolicyField.get(config); |
| 104 | + |
| 105 | + if (retryPolicy != null) { |
| 106 | + java.lang.reflect.Method getAuthManagerMethod = IterableApi.getInstance().getClass().getDeclaredMethod("getAuthManager"); |
| 107 | + getAuthManagerMethod.setAccessible(true); |
| 108 | + IterableAuthManager authManager = (IterableAuthManager) getAuthManagerMethod.invoke(IterableApi.getInstance()); |
| 109 | + |
| 110 | + if (authManager != null) { |
| 111 | + // Update the retry policy field on the authManager |
| 112 | + java.lang.reflect.Field authRetryPolicyField = authManager.getClass().getDeclaredField("authRetryPolicy"); |
| 113 | + authRetryPolicyField.setAccessible(true); |
| 114 | + authRetryPolicyField.set(authManager, retryPolicy); |
| 115 | + IterableLogger.d(TAG, "Updated retry policy on existing authManager"); |
| 116 | + } |
| 117 | + } |
| 118 | + } catch (Exception e) { |
| 119 | + IterableLogger.e(TAG, "Failed to update retry policy: " + e.getMessage()); |
| 120 | + } |
| 121 | + |
91 | 122 | IterableApi.getInstance().setDeviceAttribute("reactNativeSDKVersion", version); |
92 | 123 |
|
93 | 124 | IterableApi.getInstance().getInAppManager().addListener(this); |
@@ -121,7 +152,36 @@ public void initialize2WithApiKey(String apiKey, ReadableMap configReadableMap, |
121 | 152 | // override in the Android SDK. Check with @Ayyanchira and @evantk91 to |
122 | 153 | // see what the best approach is. |
123 | 154 |
|
124 | | - IterableApi.initialize(reactContext, apiKey, configBuilder.build()); |
| 155 | + IterableConfig config = configBuilder.build(); |
| 156 | + IterableApi.initialize(reactContext, apiKey, config); |
| 157 | + |
| 158 | + // Update retry policy on existing authManager if it was already created |
| 159 | + // This fixes the issue where retryInterval is not respected after |
| 160 | + // re-initialization |
| 161 | + // TODO [SDK-197]: Fix the root cause of this issue, instead of this hack |
| 162 | + try { |
| 163 | + // Use reflection to access package-private fields and methods |
| 164 | + java.lang.reflect.Field configRetryPolicyField = config.getClass().getDeclaredField("retryPolicy"); |
| 165 | + configRetryPolicyField.setAccessible(true); |
| 166 | + Object retryPolicy = configRetryPolicyField.get(config); |
| 167 | + |
| 168 | + if (retryPolicy != null) { |
| 169 | + java.lang.reflect.Method getAuthManagerMethod = IterableApi.getInstance().getClass().getDeclaredMethod("getAuthManager"); |
| 170 | + getAuthManagerMethod.setAccessible(true); |
| 171 | + IterableAuthManager authManager = (IterableAuthManager) getAuthManagerMethod.invoke(IterableApi.getInstance()); |
| 172 | + |
| 173 | + if (authManager != null) { |
| 174 | + // Update the retry policy field on the authManager |
| 175 | + java.lang.reflect.Field authRetryPolicyField = authManager.getClass().getDeclaredField("authRetryPolicy"); |
| 176 | + authRetryPolicyField.setAccessible(true); |
| 177 | + authRetryPolicyField.set(authManager, retryPolicy); |
| 178 | + IterableLogger.d(TAG, "Updated retry policy on existing authManager"); |
| 179 | + } |
| 180 | + } |
| 181 | + } catch (Exception e) { |
| 182 | + IterableLogger.e(TAG, "Failed to update retry policy: " + e.getMessage()); |
| 183 | + } |
| 184 | + |
125 | 185 | IterableApi.getInstance().setDeviceAttribute("reactNativeSDKVersion", version); |
126 | 186 |
|
127 | 187 | IterableApi.getInstance().getInAppManager().addListener(this); |
@@ -572,19 +632,33 @@ public String onAuthTokenRequested() { |
572 | 632 | } |
573 | 633 | } |
574 | 634 |
|
| 635 | + @Override |
| 636 | + public void onAuthFailure(AuthFailure authFailure) { |
| 637 | + // Create a JSON object for the authFailure object |
| 638 | + JSONObject messageJson = new JSONObject(); |
| 639 | + try { |
| 640 | + messageJson.put("userKey", authFailure.userKey); |
| 641 | + messageJson.put("failedAuthToken", authFailure.failedAuthToken); |
| 642 | + messageJson.put("failedRequestTime", authFailure.failedRequestTime); |
| 643 | + messageJson.put("failureReason", authFailure.failureReason.name()); |
| 644 | + WritableMap eventData = Serialization.convertJsonToMap(messageJson); |
| 645 | + sendEvent(EventName.handleAuthFailureCalled.name(), eventData); |
| 646 | + } catch (JSONException e) { |
| 647 | + IterableLogger.v(TAG, "Failed to set authToken"); |
| 648 | + } |
| 649 | + } |
| 650 | + |
| 651 | + public void pauseAuthRetries(boolean pauseRetry) { |
| 652 | + IterableApi.getInstance().pauseAuthRetries(pauseRetry); |
| 653 | + } |
| 654 | + |
575 | 655 | @Override |
576 | 656 | public void onTokenRegistrationSuccessful(String authToken) { |
577 | 657 | IterableLogger.v(TAG, "authToken successfully set"); |
578 | 658 | // MOB-10422: Pass successhandler to event listener |
579 | 659 | sendEvent(EventName.handleAuthSuccessCalled.name(), null); |
580 | 660 | } |
581 | 661 |
|
582 | | - @Override |
583 | | - public void onTokenRegistrationFailed(Throwable object) { |
584 | | - IterableLogger.v(TAG, "Failed to set authToken"); |
585 | | - sendEvent(EventName.handleAuthFailureCalled.name(), null); |
586 | | - } |
587 | | - |
588 | 662 | public void addListener(String eventName) { |
589 | 663 | // Keep: Required for RN built in Event Emitter Calls. |
590 | 664 | } |
|
0 commit comments