|
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.IterableEmbeddedMessage; |
@@ -91,11 +92,36 @@ public void initializeWithApiKey(String apiKey, ReadableMap configReadableMap, S |
91 | 92 | configBuilder.setAuthHandler(this); |
92 | 93 | } |
93 | 94 |
|
94 | | - if (configReadableMap.hasKey("enableEmbeddedMessaging")) { |
95 | | - configBuilder.setEnableEmbeddedMessaging(configReadableMap.getBoolean("enableEmbeddedMessaging")); |
| 95 | + IterableConfig config = configBuilder.build(); |
| 96 | + IterableApi.initialize(reactContext, apiKey, config); |
| 97 | + |
| 98 | + // Update retry policy on existing authManager if it was already created |
| 99 | + // This fixes the issue where retryInterval is not respected after |
| 100 | + // re-initialization |
| 101 | + // TODO [SDK-197]: Fix the root cause of this issue, instead of this hack |
| 102 | + try { |
| 103 | + // Use reflection to access package-private fields and methods |
| 104 | + java.lang.reflect.Field configRetryPolicyField = config.getClass().getDeclaredField("retryPolicy"); |
| 105 | + configRetryPolicyField.setAccessible(true); |
| 106 | + Object retryPolicy = configRetryPolicyField.get(config); |
| 107 | + |
| 108 | + if (retryPolicy != null) { |
| 109 | + java.lang.reflect.Method getAuthManagerMethod = IterableApi.getInstance().getClass().getDeclaredMethod("getAuthManager"); |
| 110 | + getAuthManagerMethod.setAccessible(true); |
| 111 | + IterableAuthManager authManager = (IterableAuthManager) getAuthManagerMethod.invoke(IterableApi.getInstance()); |
| 112 | + |
| 113 | + if (authManager != null) { |
| 114 | + // Update the retry policy field on the authManager |
| 115 | + java.lang.reflect.Field authRetryPolicyField = authManager.getClass().getDeclaredField("authRetryPolicy"); |
| 116 | + authRetryPolicyField.setAccessible(true); |
| 117 | + authRetryPolicyField.set(authManager, retryPolicy); |
| 118 | + IterableLogger.d(TAG, "Updated retry policy on existing authManager"); |
| 119 | + } |
| 120 | + } |
| 121 | + } catch (Exception e) { |
| 122 | + IterableLogger.e(TAG, "Failed to update retry policy: " + e.getMessage()); |
96 | 123 | } |
97 | 124 |
|
98 | | - IterableApi.initialize(reactContext, apiKey, configBuilder.build()); |
99 | 125 | IterableApi.getInstance().setDeviceAttribute("reactNativeSDKVersion", version); |
100 | 126 |
|
101 | 127 | IterableApi.getInstance().getInAppManager().addListener(this); |
@@ -126,15 +152,40 @@ public void initialize2WithApiKey(String apiKey, ReadableMap configReadableMap, |
126 | 152 | configBuilder.setAuthHandler(this); |
127 | 153 | } |
128 | 154 |
|
129 | | - if (configReadableMap.hasKey("enableEmbeddedMessaging")) { |
130 | | - configBuilder.setEnableEmbeddedMessaging(configReadableMap.getBoolean("enableEmbeddedMessaging")); |
131 | | - } |
132 | | - |
133 | 155 | // NOTE: There does not seem to be a way to set the API endpoint |
134 | 156 | // override in the Android SDK. Check with @Ayyanchira and @evantk91 to |
135 | 157 | // see what the best approach is. |
136 | 158 |
|
137 | | - IterableApi.initialize(reactContext, apiKey, configBuilder.build()); |
| 159 | + IterableConfig config = configBuilder.build(); |
| 160 | + IterableApi.initialize(reactContext, apiKey, config); |
| 161 | + |
| 162 | + // Update retry policy on existing authManager if it was already created |
| 163 | + // This fixes the issue where retryInterval is not respected after |
| 164 | + // re-initialization |
| 165 | + // TODO [SDK-197]: Fix the root cause of this issue, instead of this hack |
| 166 | + try { |
| 167 | + // Use reflection to access package-private fields and methods |
| 168 | + java.lang.reflect.Field configRetryPolicyField = config.getClass().getDeclaredField("retryPolicy"); |
| 169 | + configRetryPolicyField.setAccessible(true); |
| 170 | + Object retryPolicy = configRetryPolicyField.get(config); |
| 171 | + |
| 172 | + if (retryPolicy != null) { |
| 173 | + java.lang.reflect.Method getAuthManagerMethod = IterableApi.getInstance().getClass().getDeclaredMethod("getAuthManager"); |
| 174 | + getAuthManagerMethod.setAccessible(true); |
| 175 | + IterableAuthManager authManager = (IterableAuthManager) getAuthManagerMethod.invoke(IterableApi.getInstance()); |
| 176 | + |
| 177 | + if (authManager != null) { |
| 178 | + // Update the retry policy field on the authManager |
| 179 | + java.lang.reflect.Field authRetryPolicyField = authManager.getClass().getDeclaredField("authRetryPolicy"); |
| 180 | + authRetryPolicyField.setAccessible(true); |
| 181 | + authRetryPolicyField.set(authManager, retryPolicy); |
| 182 | + IterableLogger.d(TAG, "Updated retry policy on existing authManager"); |
| 183 | + } |
| 184 | + } |
| 185 | + } catch (Exception e) { |
| 186 | + IterableLogger.e(TAG, "Failed to update retry policy: " + e.getMessage()); |
| 187 | + } |
| 188 | + |
138 | 189 | IterableApi.getInstance().setDeviceAttribute("reactNativeSDKVersion", version); |
139 | 190 |
|
140 | 191 | IterableApi.getInstance().getInAppManager().addListener(this); |
|
0 commit comments