Skip to content

Commit

Permalink
fix(ios): tweak to get correct platform values on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtcoolguy committed Dec 14, 2020
1 parent 2ffbb1c commit ac8cc46
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions iphone/Classes/PlatformModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,21 @@ - (id)init
{
if (self = [super init]) {
UIDevice *theDevice = UIDevice.currentDevice;
#if !TARGET_OS_MACCATALYST
name = [theDevice.systemName retain];
version = [theDevice.systemVersion retain];

// Extract "<major>.<minor>" integers from OS version string.
NSArray *versionComponents = [version componentsSeparatedByString:@"."];
versionMajor = [NSNumber numberWithInt:[versionComponents[0] intValue]];
if ([versionComponents count] >= 2) {
versionMinor = [NSNumber numberWithInt:[versionComponents[1] intValue]];
if ([versionComponents count] >= 3) {
versionPatch = [NSNumber numberWithInt:[versionComponents[2] intValue]];
} else {
versionPatch = @0;
}
} else {
versionMinor = @0;
versionPatch = @0;
}
#else
name = @"Mac OS X";
#endif

// grab logical CPUs
int cores = 1;
size_t sizeof_cores = sizeof(cores);
sysctlbyname("hw.logicalcpu_max", &cores, &sizeof_cores, NULL, 0);
if (cores <= 0) {
cores = 1;
}
processorCount = [[NSNumber numberWithInt:cores] retain];
NSOperatingSystemVersion versionStruct = NSProcessInfo.processInfo.operatingSystemVersion;
version = [[NSString stringWithFormat:@"%ld.%ld.%ld", versionStruct.majorVersion, versionStruct.minorVersion, versionStruct.patchVersion] retain];
versionMajor = [NSNumber numberWithInteger:versionStruct.majorVersion];
versionMinor = [NSNumber numberWithInteger:versionStruct.minorVersion];
versionPatch = [NSNumber numberWithInteger:versionStruct.patchVersion];
processorCount = [NSNumber numberWithUnsignedInteger:NSProcessInfo.processInfo.processorCount];

username = [theDevice.name retain];

#ifdef __LP64__
ostype = [@"64bit" retain];
#else
Expand All @@ -79,16 +66,27 @@ - (id)init
osname = [@"iphone" retain];
}

NSString *themodel = theDevice.model;

// attempt to determine extended phone info
struct utsname u;
uname(&u);

// detect simulator
#if TARGET_OS_SIMULATOR
model = [[NSString stringWithFormat:@"%s (Simulator)", getenv("SIMULATOR_MODEL_IDENTIFIER")] retain];
#elif TARGET_OS_MACCATALYST
// Need to go a bit deeper to get the hardware model for actual macOS boxes
const char *keyCString = "hw.model";
NSString *answer = @"";

size_t length;
sysctlbyname(keyCString, NULL, &length, NULL, 0);
if (length) {
char *answerCString = malloc(length * sizeof(char));
sysctlbyname(keyCString, answerCString, &length, NULL, 0);
answer = [NSString stringWithCString:answerCString encoding:NSUTF8StringEncoding];
free(answerCString);
}
model = [answer retain];
#else
// attempt to determine extended phone info
struct utsname u;
uname(&u);
model = [[NSString alloc] initWithUTF8String:u.machine];
#endif
architecture = [[TiUtils currentArchitecture] retain];
Expand Down

0 comments on commit ac8cc46

Please sign in to comment.