From b096d2fdfc423eefd2d148036b7e8dfdc6e26f2a Mon Sep 17 00:00:00 2001 From: stevepodell Date: Tue, 6 Oct 2020 12:11:04 -0700 Subject: [PATCH 1/5] Initial checking, adding isiOSAppOnMac detection --- src/ios/CDVDevice.m | 18 +++++++++++++++--- www/device.js | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ios/CDVDevice.m b/src/ios/CDVDevice.m index de535332..643192b8 100644 --- a/src/ios/CDVDevice.m +++ b/src/ios/CDVDevice.m @@ -53,7 +53,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 +69,7 @@ - (NSString*)uniqueAppInstanceIdentifier:(UIDevice*)device [userDefaults setObject:app_uuid forKey:UUID_KEY]; [userDefaults synchronize]; } - + return app_uuid; } @@ -92,7 +92,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 +113,15 @@ - (BOOL)isVirtual #endif } + +- (BOOL) isiOSAppOnMac +{ + if (@available(iOS 14.0, *)) { + return [NSProcessInfo processInfo].isiOSAppOnMac; + } else { + // Fallback on earlier versions + return false; + } +} + @end diff --git a/www/device.js b/www/device.js index b05c0cbe..75ef30ef 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,7 @@ function Device () { me.cordova = buildLabel; me.model = info.model; me.isVirtual = info.isVirtual; + me.isiOSAppOnMac = info.isiOSAppOnMac || false; me.manufacturer = info.manufacturer || 'unknown'; me.serial = info.serial || 'unknown'; From e9c4649a3aa80fc9fa22efe9429fd90114441de4 Mon Sep 17 00:00:00 2001 From: stevepodell Date: Thu, 15 Oct 2020 10:50:35 -0700 Subject: [PATCH 2/5] Adds isiOSAppOnMac detection --- README.md | 13 +++++++++++++ src/ios/CDVDevice.m | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e38575c1..5a9cf505 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 + +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. + +```js +var boolean = device.isiOSAppOnMac; +``` + +### Supported Platforms + +- iOS diff --git a/src/ios/CDVDevice.m b/src/ios/CDVDevice.m index 643192b8..675693a3 100644 --- a/src/ios/CDVDevice.m +++ b/src/ios/CDVDevice.m @@ -119,7 +119,7 @@ - (BOOL) isiOSAppOnMac if (@available(iOS 14.0, *)) { return [NSProcessInfo processInfo].isiOSAppOnMac; } else { - // Fallback on earlier versions + // Fallback on earlier versions, and platforms return false; } } From 3c6a3ad3fecdccdf781af785d34e999bca553fbc Mon Sep 17 00:00:00 2001 From: Steve Podell Date: Mon, 4 Apr 2022 09:24:57 -0700 Subject: [PATCH 3/5] Update www/device.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: エリス --- www/device.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/www/device.js b/www/device.js index 75ef30ef..7e67edbd 100644 --- a/www/device.js +++ b/www/device.js @@ -60,7 +60,10 @@ function Device () { me.cordova = buildLabel; me.model = info.model; me.isVirtual = info.isVirtual; - me.isiOSAppOnMac = info.isiOSAppOnMac || false; + // 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'; From 396e8c7fd89f882fe15fc3b1b87311b6656748cb Mon Sep 17 00:00:00 2001 From: stevepodell Date: Mon, 4 Apr 2022 09:35:00 -0700 Subject: [PATCH 4/5] 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 5a9cf505..ac8cacf9 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 9e2d6899..0cef13a4 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 From 8938cf78de78178dd657273596ae48054ed51b6f Mon Sep 17 00:00:00 2001 From: Erisu Date: Wed, 6 Apr 2022 13:33:21 +0900 Subject: [PATCH 5/5] fix: gh-action failing to find isiOSAppOnMac on processInfo --- src/ios/CDVDevice.m | 11 +++++++---- src/osx/CDVDevice.m | 14 +++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/ios/CDVDevice.m b/src/ios/CDVDevice.m index 675693a3..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" @@ -116,12 +118,13 @@ - (BOOL)isVirtual - (BOOL) isiOSAppOnMac { + #if __IPHONE_14_0 if (@available(iOS 14.0, *)) { - return [NSProcessInfo processInfo].isiOSAppOnMac; - } else { - // Fallback on earlier versions, and platforms - return false; + return [[NSProcessInfo processInfo] isiOSAppOnMac]; } + #endif + + return false; } @end diff --git a/src/osx/CDVDevice.m b/src/osx/CDVDevice.m index 0cef13a4..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" @@ -110,13 +112,15 @@ + (NSString*) cordovaVersion { return CDV_VERSION; } -+ (BOOL) isiOSAppOnMac { +- (BOOL) isiOSAppOnMac +{ + #if __IPHONE_14_0 if (@available(iOS 14.0, *)) { - return [NSProcessInfo processInfo].isiOSAppOnMac; - } else { - // Fallback on earlier versions and platforms - return false; + return [[NSProcessInfo processInfo] isiOSAppOnMac]; } + #endif + + return false; } @end