You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2022/04/07 08:55:21 UTC

[cordova-plugin-device] branch master updated: feat(ios): detect if app is running on a macOS desktop with Apple Silicon (#167)

This is an automated email from the ASF dual-hosted git repository.

erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-device.git


The following commit(s) were added to refs/heads/master by this push:
     new 6b09b88  feat(ios): detect if app is running on a macOS desktop with Apple Silicon (#167)
6b09b88 is described below

commit 6b09b888d4d2cc2f715d44355cba151d091d762f
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Thu Apr 7 17:55:14 2022 +0900

    feat(ios): detect if app is running on a macOS desktop with Apple Silicon (#167)
    
    * Initial checking, adding isiOSAppOnMac detection
    * Adds isiOSAppOnMac detection
    * Update www/device.js
    * Adds isiOSAppOnMac detection
       Rebased, and includes the suggestion from erisu
    * fix: gh-action failing to find isiOSAppOnMac on processInfo
    
    Co-authored-by: stevepodell <st...@podell.com>
---
 README.md           | 13 +++++++++++++
 src/ios/CDVDevice.m | 21 ++++++++++++++++++---
 src/osx/CDVDevice.m | 15 ++++++++++++++-
 www/device.js       |  5 +++++
 4 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index e38575c..ac8cacf 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 de53533..7315489 100644
--- a/src/ios/CDVDevice.m
+++ b/src/ios/CDVDevice.m
@@ -21,6 +21,8 @@
 #include <sys/sysctl.h>
 #include "TargetConditionals.h"
 
+#import <Availability.h>
+
 #import <Cordova/CDV.h>
 #import "CDVDevice.h"
 
@@ -53,7 +55,7 @@
 {
     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 @@
         [userDefaults setObject:app_uuid forKey:UUID_KEY];
         [userDefaults synchronize];
     }
-    
+
     return app_uuid;
 }
 
@@ -92,7 +94,8 @@
              @"version": [device systemVersion],
              @"uuid": [self uniqueAppInstanceIdentifier:device],
              @"cordova": [[self class] cordovaVersion],
-             @"isVirtual": @([self isVirtual])
+             @"isVirtual": @([self isVirtual]),
+             @"isiOSAppOnMac": @([self isiOSAppOnMac])
              };
 }
 
@@ -112,4 +115,16 @@
     #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 9e2d689..dd6f811 100644
--- a/src/osx/CDVDevice.m
+++ b/src/osx/CDVDevice.m
@@ -19,6 +19,8 @@
 
 #include <sys/sysctl.h>
 
+#import <Availability.h>
+
 #import "CDVDevice.h"
 
 #define SYSTEM_VERSION_PLIST    @"/System/Library/CoreServices/SystemVersion.plist"
@@ -37,7 +39,6 @@
     return modelVersion;
 }
 
-
 - (NSString*) getSerialNr {
     NSString* serialNr;
     io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
@@ -101,6 +102,7 @@
     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 @@
     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 b05c0cb..7e67edb 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';
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org