Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ class PackageInfo {
/// The time when the application was installed.
///
/// - On Android, returns `PackageManager.firstInstallTime`
/// - On iOS and macOS, return the creation date of the app default `NSDocumentDirectory`
/// - On iOS, return the creation date of the app default `NSDocumentDirectory`
/// - On macOS, if the app is running in sandbox, return the creation date of the app default `NSDocumentDirectory`;
/// If the app is not running in sandbox, return the last modified date of the app main bundle
/// - On Windows and Linux, returns the creation date of the app executable.
/// If the creation date is not available, returns the last modified date of the app executable.
/// If the last modified date is not available, returns `null`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
- (void)handleMethodCall:(FlutterMethodCall *)call
result:(FlutterResult)result {
if ([call.method isEqualToString:@"getAll"]) {
NSDate *installDate = [self getInstallDate];
NSDate *updateDate = [self getUpdateDate];
NSString *installDateStr = [self getTimeMillisStringFromDate:[self getInstallDate]];
NSString *updateDateStr = [self getTimeMillisStringFromDate:[self getUpdateDate]];

result(@{
@"appName" : [[NSBundle mainBundle]
Expand All @@ -33,15 +33,19 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
objectForInfoDictionaryKey:@"CFBundleVersion"]
?: [NSNull null],
@"installerStore" : [NSNull null],
@"installTime" : [self getTimeMillisStringFromDate:installDate] ?: [NSNull null],
@"updateTime" : [self getTimeMillisStringFromDate:updateDate] ?: [NSNull null]
@"installTime" : installDateStr ?: updateDateStr ?: [NSNull null],
@"updateTime" : updateDateStr ?: [NSNull null]
});
} else {
result(FlutterMethodNotImplemented);
}
}

- (NSDate *)getInstallDate {
if (![self isRunningInSandbox]) {
return nil;
}

NSURL* urlToDocumentsFolder = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
__autoreleasing NSError *error;
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:urlToDocumentsFolder.path error:&error];
Expand Down Expand Up @@ -74,4 +78,9 @@ - (NSString *)getTimeMillisStringFromDate:(NSDate *)date {
return [timeMillis stringValue];
}

- (BOOL)isRunningInSandbox {
NSString *sandboxContainerId = [[[NSProcessInfo processInfo] environment] objectForKey:@"APP_SANDBOX_CONTAINER_ID"];
return sandboxContainerId != nil;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class PackageInfoData {
/// The time when the application was installed.
///
/// - On Android, returns `PackageManager.firstInstallTime`
/// - On iOS and macOS, return the creation date of the app default `NSDocumentDirectory`
/// - On iOS, return the creation date of the app default `NSDocumentDirectory`
/// - On macOS, if the app is running in sandbox, return the creation date of the app default `NSDocumentDirectory`;
/// If the app is not running in sandbox, return the last modified date of the app main bundle
/// - On Windows and Linux, returns the creation date of the app executable.
/// If the creation date is not available, returns the last modified date of the app executable.
/// If the last modified date is not available, returns `null`.
Expand Down