diff --git a/README.md b/README.md index e38575c1..ac8cacf9 100644 --- a/README.md +++ b/README.md @@ -294,3 +294,16 @@ var string = device.serial; ### Android Quirk As of Android 9, the underlying native API that powered the `uuid` property is deprecated and will always return `UNKNOWN` without proper permissions. Cordova have never implemented handling the required permissions. As of Android 10, **all** non-resettable device identifiers are no longer readable by normal applications and will always return `UNKNOWN`. More information can be [read here](https://developer.android.com/about/versions/10/privacy/changes#non-resettable-device-ids). + +## device.isiOSAppOnMac + +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; +``` + +### Supported Platforms + +- iOS diff --git a/src/ios/CDVDevice.m b/src/ios/CDVDevice.m index de535332..73154897 100644 --- a/src/ios/CDVDevice.m +++ b/src/ios/CDVDevice.m @@ -21,6 +21,8 @@ Licensed to the Apache Software Foundation (ASF) under one #include #include "TargetConditionals.h" +#import + #import #import "CDVDevice.h" @@ -53,7 +55,7 @@ - (NSString*)uniqueAppInstanceIdentifier:(UIDevice*)device { NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; static NSString* UUID_KEY = @"CDVUUID"; - + // Check user defaults first to maintain backwards compaitibility with previous versions // which didn't user identifierForVendor NSString* app_uuid = [userDefaults stringForKey:UUID_KEY]; @@ -69,7 +71,7 @@ - (NSString*)uniqueAppInstanceIdentifier:(UIDevice*)device [userDefaults setObject:app_uuid forKey:UUID_KEY]; [userDefaults synchronize]; } - + return app_uuid; } @@ -92,7 +94,8 @@ - (NSDictionary*)deviceProperties @"version": [device systemVersion], @"uuid": [self uniqueAppInstanceIdentifier:device], @"cordova": [[self class] cordovaVersion], - @"isVirtual": @([self isVirtual]) + @"isVirtual": @([self isVirtual]), + @"isiOSAppOnMac": @([self isiOSAppOnMac]) }; } @@ -112,4 +115,16 @@ - (BOOL)isVirtual #endif } + +- (BOOL) isiOSAppOnMac +{ + #if __IPHONE_14_0 + if (@available(iOS 14.0, *)) { + return [[NSProcessInfo processInfo] isiOSAppOnMac]; + } + #endif + + return false; +} + @end diff --git a/src/osx/CDVDevice.m b/src/osx/CDVDevice.m index 9e2d6899..dd6f811f 100644 --- a/src/osx/CDVDevice.m +++ b/src/osx/CDVDevice.m @@ -19,6 +19,8 @@ Licensed to the Apache Software Foundation (ASF) under one #include +#import + #import "CDVDevice.h" #define SYSTEM_VERSION_PLIST @"/System/Library/CoreServices/SystemVersion.plist" @@ -37,7 +39,6 @@ - (NSString*) modelVersion { return modelVersion; } - - (NSString*) getSerialNr { NSString* serialNr; io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")); @@ -101,6 +102,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 +112,15 @@ + (NSString*) cordovaVersion { return CDV_VERSION; } +- (BOOL) isiOSAppOnMac +{ + #if __IPHONE_14_0 + if (@available(iOS 14.0, *)) { + return [[NSProcessInfo processInfo] isiOSAppOnMac]; + } + #endif + + return false; +} + @end diff --git a/www/device.js b/www/device.js index b05c0cbe..7e67edbd 100644 --- a/www/device.js +++ b/www/device.js @@ -43,6 +43,7 @@ function Device () { this.manufacturer = null; this.isVirtual = null; this.serial = null; + this.isiOSAppOnMac = null; var me = this; @@ -59,6 +60,10 @@ function Device () { me.cordova = buildLabel; me.model = info.model; me.isVirtual = info.isVirtual; + // isiOSAppOnMac is iOS specific. If defined, it will be appended. + if (info.isiOSAppOnMac !== undefined) { + me.isiOSAppOnMac = info.isiOSAppOnMac; + } me.manufacturer = info.manufacturer || 'unknown'; me.serial = info.serial || 'unknown';