Skip to content

Commit

Permalink
Merge pull request #363 from VismaLietuva/getInfoForiOS
Browse files Browse the repository at this point in the history
(iOS) Add `getInfo()` for iOS (since Android has it already)
  • Loading branch information
dpa99c authored Apr 10, 2020
2 parents b6ee144 + d9bd6ea commit 7118d8c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2532,7 +2532,6 @@ FirebasePlugin.getByteArray("key", function(bytes) {
```

### getInfo
Android only.
Get the current state of the FirebaseRemoteConfig singleton object:

**Parameters**:
Expand All @@ -2543,6 +2542,10 @@ Get the current state of the FirebaseRemoteConfig singleton object:
FirebasePlugin.getInfo(function(info) {
// the status of the developer mode setting (true/false)
console.log(info.configSettings.developerModeEnabled);
// (iOS only) for how much (secs) fetch cache is valid and data will not be refetched
console.log(info.configSettings.minimumFetchInterval);
// (iOS only) value in seconds to abandon a pending fetch request made to the backend
console.log(info.configSettings.fetchTimeout);
// the timestamp (milliseconds since epoch) of the last successful fetch
console.log(info.fetchTimeMillis);
// the status of the most recent fetch attempt (int)
Expand Down
1 change: 1 addition & 0 deletions src/ios/FirebasePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
- (void)fetch:(CDVInvokedUrlCommand*)command;
- (void)activateFetched:(CDVInvokedUrlCommand*)command;
- (void)getValue:(CDVInvokedUrlCommand*)command;
- (void)getInfo:(CDVInvokedUrlCommand*)command;

// Performance
- (void)setPerformanceCollectionEnabled:(CDVInvokedUrlCommand*)command;
Expand Down
31 changes: 31 additions & 0 deletions src/ios/FirebasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,37 @@ - (void)getValue:(CDVInvokedUrlCommand *)command {
}];
}

- (void)getInfo:(CDVInvokedUrlCommand *)command {
[self.commandDelegate runInBackground:^{
@try {
FIRRemoteConfig* remoteConfig = [FIRRemoteConfig remoteConfig];
NSInteger minimumFetchInterval = remoteConfig.configSettings.minimumFetchInterval;
NSInteger fetchTimeout = remoteConfig.configSettings.fetchTimeout;
NSDate* lastFetchTime = remoteConfig.lastFetchTime;
FIRRemoteConfigFetchStatus lastFetchStatus = remoteConfig.lastFetchStatus;
// isDeveloperModeEnabled is deprecated new recommnded way to check is minimumFetchInterval == 0
BOOL isDeveloperModeEnabled = minimumFetchInterval == 0 ? true : false;

NSDictionary* configSettings = @{
@"developerModeEnabled": [NSNumber numberWithBool:isDeveloperModeEnabled],
@"minimumFetchInterval": [NSNumber numberWithInteger:minimumFetchInterval],
@"fetchTimeout": [NSNumber numberWithInteger:fetchTimeout],
};

NSDictionary* infoObject = @{
@"configSettings": configSettings,
@"fetchTimeMillis": (lastFetchTime ? [NSNumber numberWithInteger:(lastFetchTime.timeIntervalSince1970 * 1000)] : [NSNull null]),
@"lastFetchStatus": [NSNumber numberWithInteger:(lastFetchStatus)],
};

CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:infoObject];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}@catch (NSException *exception) {
[self handlePluginExceptionWithContext:exception :command];
}
}];
}

/*
* Performance
*/
Expand Down

0 comments on commit 7118d8c

Please sign in to comment.