From 396e8c7fd89f882fe15fc3b1b87311b6656748cb Mon Sep 17 00:00:00 2001 From: stevepodell Date: Mon, 4 Apr 2022 09:35:00 -0700 Subject: [PATCH] Adds isiOSAppOnMac detection Rebased, and includes the suggestion from erisu --- README.md | 4 ++-- src/osx/CDVDevice.m | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5a9cf50..ac8cacf 100644 --- a/README.md +++ b/README.md @@ -297,8 +297,8 @@ As of Android 9, the underlying native API that powered the `uuid` property is d ## device.isiOSAppOnMac -Is the iOS app running on the Mac desktop? Will only return true on a Mac with an ARM64 processor (Apple Silicon). -Returns false for all other platforms. +The iOS app is running on the Mac desktop (Apple Silicon ARM64 processor, M1 or newer). +This parameter is only returned for iOS V14.0 or later, and is not returned for Android devices. ```js var boolean = device.isiOSAppOnMac; diff --git a/src/osx/CDVDevice.m b/src/osx/CDVDevice.m index 9e2d689..0cef13a 100644 --- a/src/osx/CDVDevice.m +++ b/src/osx/CDVDevice.m @@ -37,7 +37,6 @@ - (NSString*) modelVersion { return modelVersion; } - - (NSString*) getSerialNr { NSString* serialNr; io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")); @@ -101,6 +100,7 @@ - (NSDictionary*) deviceProperties { devProps[@"cordova"] = [[self class] cordovaVersion]; devProps[@"serial"] = [self getSerialNr]; devProps[@"isVirtual"] = @NO; + devProps[@"isiOSAppOnMac"]: [self isiOSAppOnMac]; NSDictionary* devReturn = [NSDictionary dictionaryWithDictionary:devProps]; return devReturn; @@ -110,4 +110,13 @@ + (NSString*) cordovaVersion { return CDV_VERSION; } ++ (BOOL) isiOSAppOnMac { + if (@available(iOS 14.0, *)) { + return [NSProcessInfo processInfo].isiOSAppOnMac; + } else { + // Fallback on earlier versions and platforms + return false; + } +} + @end