In Apptimize SDK version 3.7.0 (Android) / 3.4.0 (iOS) we added metadata state monitoring functions, which can be leveraged to ensure that users who are returning your app from the background will receive the latest version of their Feature Flag / Experiment configuration (aka experiment 'metadata') before the app session is reinitialized.
For additional details see the documentation for -
Android: Apptimize.getMetadataState, Apptimize.addOnMetadataStateChangedListener and Apptimize.removeOnMetadataStateChangedListener
iOS: Apptimize.metadataState, Apptimize.ApptimizeMetadataStateChangedNotification and Apptimize.ApptimizeResumedNotification
An example of how this would be used on iOS:
# Waiting for Metadata on Resume
1. Your app should register for `UIApplication.willResignActiveNotification`. When entering this state you should no longer make calls to Apptimize APIs.
2. Your app should register for `ApptimizeResumedNotification`. When this notification is received, you should check the `ApptimizeWillRefreshMetadataKey` property to determine if apptimize is checking for updated metadata. If it is not checking, you can make calls to apptimize APIs.
3. Your app should register for `ApptimizeMetadataStateChangedNotification`. If apptimize is refreshing metadata, you can monitor this notification to determine when that refresh has been completed. Check the `ApptimizeMetadataStateFlagsKey` and wait until the flag `ApptimizeMetadataStateRefreshing` has been cleared.
**Pseudocode**
```
bool canCallApptimize = true;
onWillResignActiveNotification() {
canCallApptimize = false;
}
onApptimizeResumedNotification(willRefreshMetadata) {
canCallApptimize = !willRefreshMetadata;
// You could set a timeout here so you don't wait forever. The refresh may continue
// for the length of a very long network transaction.
}
onApptimizeMetadataStateChangedNotification(metadataStateFlags) {
if (metadataStateFlags & ApptimizeMetadataStateRefreshing) {
// Keep waiting...
} else if (canCallApptimize == false) {
canCallApptimize = true;
notifyApplication();
}
}
Comments
0 comments
Please sign in to leave a comment.