|
26 | 26 | import com.iterable.iterableapi.IterableApi; |
27 | 27 | import com.iterable.iterableapi.IterableAttributionInfo; |
28 | 28 | import com.iterable.iterableapi.IterableAuthHandler; |
| 29 | +import com.iterable.iterableapi.IterableAuthManager; |
29 | 30 | import com.iterable.iterableapi.IterableConfig; |
30 | 31 | import com.iterable.iterableapi.IterableCustomActionHandler; |
31 | 32 | // import com.iterable.iterableapi.IterableEmbeddedManager; |
@@ -98,7 +99,40 @@ public void initializeWithApiKey(String apiKey, ReadableMap configReadableMap, S |
98 | 99 | configBuilder.setEnableEmbeddedMessaging(configReadableMap.getBoolean("enableEmbeddedMessaging")); |
99 | 100 | } |
100 | 101 |
|
101 | | - IterableApi.initialize(reactContext, apiKey, configBuilder.build()); |
| 102 | + if (configReadableMap.hasKey("enableEmbeddedMessaging")) { |
| 103 | + configBuilder.setEnableEmbeddedMessaging(configReadableMap.getBoolean("enableEmbeddedMessaging")); |
| 104 | + } |
| 105 | + |
| 106 | + IterableConfig config = configBuilder.build(); |
| 107 | + IterableApi.initialize(reactContext, apiKey, config); |
| 108 | + |
| 109 | + // Update retry policy on existing authManager if it was already created |
| 110 | + // This fixes the issue where retryInterval is not respected after |
| 111 | + // re-initialization |
| 112 | + // TODO [SDK-197]: Fix the root cause of this issue, instead of this hack |
| 113 | + try { |
| 114 | + // Use reflection to access package-private fields and methods |
| 115 | + java.lang.reflect.Field configRetryPolicyField = config.getClass().getDeclaredField("retryPolicy"); |
| 116 | + configRetryPolicyField.setAccessible(true); |
| 117 | + Object retryPolicy = configRetryPolicyField.get(config); |
| 118 | + |
| 119 | + if (retryPolicy != null) { |
| 120 | + java.lang.reflect.Method getAuthManagerMethod = IterableApi.getInstance().getClass().getDeclaredMethod("getAuthManager"); |
| 121 | + getAuthManagerMethod.setAccessible(true); |
| 122 | + IterableAuthManager authManager = (IterableAuthManager) getAuthManagerMethod.invoke(IterableApi.getInstance()); |
| 123 | + |
| 124 | + if (authManager != null) { |
| 125 | + // Update the retry policy field on the authManager |
| 126 | + java.lang.reflect.Field authRetryPolicyField = authManager.getClass().getDeclaredField("authRetryPolicy"); |
| 127 | + authRetryPolicyField.setAccessible(true); |
| 128 | + authRetryPolicyField.set(authManager, retryPolicy); |
| 129 | + IterableLogger.d(TAG, "Updated retry policy on existing authManager"); |
| 130 | + } |
| 131 | + } |
| 132 | + } catch (Exception e) { |
| 133 | + IterableLogger.e(TAG, "Failed to update retry policy: " + e.getMessage()); |
| 134 | + } |
| 135 | + |
102 | 136 | IterableApi.getInstance().setDeviceAttribute("reactNativeSDKVersion", version); |
103 | 137 |
|
104 | 138 | IterableApi.getInstance().getInAppManager().addListener(this); |
@@ -137,7 +171,36 @@ public void initialize2WithApiKey(String apiKey, ReadableMap configReadableMap, |
137 | 171 | // override in the Android SDK. Check with @Ayyanchira and @evantk91 to |
138 | 172 | // see what the best approach is. |
139 | 173 |
|
140 | | - IterableApi.initialize(reactContext, apiKey, configBuilder.build()); |
| 174 | + IterableConfig config = configBuilder.build(); |
| 175 | + IterableApi.initialize(reactContext, apiKey, config); |
| 176 | + |
| 177 | + // Update retry policy on existing authManager if it was already created |
| 178 | + // This fixes the issue where retryInterval is not respected after |
| 179 | + // re-initialization |
| 180 | + // TODO [SDK-197]: Fix the root cause of this issue, instead of this hack |
| 181 | + try { |
| 182 | + // Use reflection to access package-private fields and methods |
| 183 | + java.lang.reflect.Field configRetryPolicyField = config.getClass().getDeclaredField("retryPolicy"); |
| 184 | + configRetryPolicyField.setAccessible(true); |
| 185 | + Object retryPolicy = configRetryPolicyField.get(config); |
| 186 | + |
| 187 | + if (retryPolicy != null) { |
| 188 | + java.lang.reflect.Method getAuthManagerMethod = IterableApi.getInstance().getClass().getDeclaredMethod("getAuthManager"); |
| 189 | + getAuthManagerMethod.setAccessible(true); |
| 190 | + IterableAuthManager authManager = (IterableAuthManager) getAuthManagerMethod.invoke(IterableApi.getInstance()); |
| 191 | + |
| 192 | + if (authManager != null) { |
| 193 | + // Update the retry policy field on the authManager |
| 194 | + java.lang.reflect.Field authRetryPolicyField = authManager.getClass().getDeclaredField("authRetryPolicy"); |
| 195 | + authRetryPolicyField.setAccessible(true); |
| 196 | + authRetryPolicyField.set(authManager, retryPolicy); |
| 197 | + IterableLogger.d(TAG, "Updated retry policy on existing authManager"); |
| 198 | + } |
| 199 | + } |
| 200 | + } catch (Exception e) { |
| 201 | + IterableLogger.e(TAG, "Failed to update retry policy: " + e.getMessage()); |
| 202 | + } |
| 203 | + |
141 | 204 | IterableApi.getInstance().setDeviceAttribute("reactNativeSDKVersion", version); |
142 | 205 |
|
143 | 206 | IterableApi.getInstance().getInAppManager().addListener(this); |
@@ -616,11 +679,6 @@ public void onTokenRegistrationSuccessful(String authToken) { |
616 | 679 | sendEvent(EventName.handleAuthSuccessCalled.name(), null); |
617 | 680 | } |
618 | 681 |
|
619 | | - public void onTokenRegistrationFailed(Throwable object) { |
620 | | - IterableLogger.v(TAG, "Failed to set authToken"); |
621 | | - sendEvent(EventName.handleAuthFailureCalled.name(), null); |
622 | | - } |
623 | | - |
624 | 682 | public void addListener(String eventName) { |
625 | 683 | // Keep: Required for RN built in Event Emitter Calls. |
626 | 684 | } |
|
0 commit comments