Skip to content

Commit

Permalink
feat(ios, firstInstallTime): implement first install time for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehardy committed Sep 18, 2022
1 parent 0c63c9b commit 63b9feb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -140,7 +140,7 @@ The example app in this repository shows an example usage of every single API, c
| [getDisplay()](#getdisplay) | `Promise<string>` |||||
| [getDeviceName()](#getdevicename) | `Promise<string>` |||||
| [getDeviceToken()](#getdevicetoken) | `Promise<string>` |||||
| [getFirstInstallTime()](#getfirstinstalltime) | `Promise<number>` | ||||
| [getFirstInstallTime()](#getfirstinstalltime) | `Promise<number>` | ||||
| [getFingerprint()](#getfingerprint) | `Promise<string>` |||||
| [getFontScale()](#getfontscale) | `Promise<number>` |||||
| [getFreeDiskStorage()](#getfreediskstorage) | `Promise<number>` |||||
Expand Down
15 changes: 15 additions & 0 deletions ios/RNDeviceInfo/RNDeviceInfo.m
Expand Up @@ -857,6 +857,21 @@ - (NSNumber *) getBrightness {
resolve(self.getBrightness);
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getFirstInstallTimeSync) {
return @(self.getFirstInstallTime);
}

RCT_EXPORT_METHOD(getFirstInstallTime:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
resolve(@(self.getFirstInstallTime));
}

- (long long) getFirstInstallTime {
NSURL* urlToDocumentsFolder = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSError *error;
NSDate *installDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:urlToDocumentsFolder.path error:&error] objectForKey:NSFileCreationDate];
return [@(floor([installDate timeIntervalSince1970] * 1000)) longLongValue];
}

#pragma mark - dealloc -

- (void)dealloc
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -429,7 +429,7 @@ export const [hasHms, hasHmsSync] = getSupportedPlatformInfoFunctions({

export const [getFirstInstallTime, getFirstInstallTimeSync] = getSupportedPlatformInfoFunctions({
memoKey: 'firstInstallTime',
supportedPlatforms: ['android', 'windows'],
supportedPlatforms: ['android', 'ios', 'windows'],
getter: () => RNDeviceInfo.getFirstInstallTime(),
syncGetter: () => RNDeviceInfo.getFirstInstallTimeSync(),
defaultValue: -1,
Expand Down

0 comments on commit 63b9feb

Please sign in to comment.