|
24 | 24 | import com.iterable.iterableapi.IterableActionContext; |
25 | 25 | import com.iterable.iterableapi.IterableApi; |
26 | 26 | import com.iterable.iterableapi.IterableAuthHandler; |
| 27 | +import com.iterable.iterableapi.IterableAuthManager; |
27 | 28 | import com.iterable.iterableapi.IterableConfig; |
28 | 29 | import com.iterable.iterableapi.IterableCustomActionHandler; |
29 | 30 | import com.iterable.iterableapi.IterableAttributionInfo; |
@@ -88,7 +89,36 @@ public void initializeWithApiKey(String apiKey, ReadableMap configReadableMap, S |
88 | 89 | configBuilder.setAuthHandler(this); |
89 | 90 | } |
90 | 91 |
|
91 | | - 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 | + |
92 | 122 | IterableApi.getInstance().setDeviceAttribute("reactNativeSDKVersion", version); |
93 | 123 |
|
94 | 124 | IterableApi.getInstance().getInAppManager().addListener(this); |
@@ -122,7 +152,36 @@ public void initialize2WithApiKey(String apiKey, ReadableMap configReadableMap, |
122 | 152 | // override in the Android SDK. Check with @Ayyanchira and @evantk91 to |
123 | 153 | // see what the best approach is. |
124 | 154 |
|
125 | | - 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 | + |
126 | 185 | IterableApi.getInstance().setDeviceAttribute("reactNativeSDKVersion", version); |
127 | 186 |
|
128 | 187 | IterableApi.getInstance().getInAppManager().addListener(this); |
|
0 commit comments