|
| 1 | +#import "CDVBuildInfo.h" |
| 2 | + |
| 3 | +@implementation CDVBuildInfo |
| 4 | + |
| 5 | +- (void)init:(CDVInvokedUrlCommand *)command { |
| 6 | + NSDictionary *info = [[NSBundle mainBundle] infoDictionary]; |
| 7 | + NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier] ?: @""; |
| 8 | + NSString *displayName = info[@"CFBundleDisplayName"] ?: info[@"CFBundleName"] ?: @""; |
| 9 | + NSString *name = info[@"CFBundleName"] ?: @""; |
| 10 | + NSString *version = info[@"CFBundleShortVersionString"] ?: @""; |
| 11 | + NSString *build = info[@"CFBundleVersion"] ?: @""; |
| 12 | + |
| 13 | +#ifdef DEBUG |
| 14 | + NSNumber *debug = @YES; |
| 15 | + NSString *buildType = @"debug"; |
| 16 | +#else |
| 17 | + NSNumber *debug = @NO; |
| 18 | + NSString *buildType = @"release"; |
| 19 | +#endif |
| 20 | + |
| 21 | + NSString *installDateString = @""; |
| 22 | + NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; |
| 23 | + NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:bundlePath error:nil]; |
| 24 | + NSDate *installDate = attrs[NSFileCreationDate]; |
| 25 | + if (installDate) { |
| 26 | + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; |
| 27 | + formatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]; |
| 28 | + formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"; |
| 29 | + installDateString = [formatter stringFromDate:installDate] ?: @""; |
| 30 | + } |
| 31 | + |
| 32 | + NSDictionary *payload = @{ |
| 33 | + @"packageName": bundleId, |
| 34 | + @"basePackageName": bundleId, |
| 35 | + @"displayName": displayName, |
| 36 | + @"name": name, |
| 37 | + @"version": version, |
| 38 | + @"versionCode": build, |
| 39 | + @"debug": debug, |
| 40 | + @"buildType": buildType, |
| 41 | + @"flavor": @"", |
| 42 | + @"installDate": installDateString |
| 43 | + }; |
| 44 | + |
| 45 | + CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:payload]; |
| 46 | + [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; |
| 47 | +} |
| 48 | + |
| 49 | +@end |
0 commit comments