Skip to content

Commit

Permalink
Adds isiOSAppOnMac detection
Browse files Browse the repository at this point in the history
Rebased, and includes the suggestion from erisu
  • Loading branch information
SailingSteve authored and erisu committed Apr 6, 2022
1 parent 3c6a3ad commit 396e8c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/osx/CDVDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ - (NSString*) modelVersion {
return modelVersion;
}


- (NSString*) getSerialNr {
NSString* serialNr;
io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
Expand Down Expand Up @@ -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;
Expand All @@ -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

0 comments on commit 396e8c7

Please sign in to comment.