Skip to content

Commit e907784

Browse files
authored
feat(device_info_plus): Add the isiOSAppOnMac property for the iOS platform. (#3383)
1 parent 3d06bf0 commit e907784

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

packages/device_info_plus/device_info_plus/example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class _MyAppState extends State<MyApp> {
115115
'localizedModel': data.localizedModel,
116116
'identifierForVendor': data.identifierForVendor,
117117
'isPhysicalDevice': data.isPhysicalDevice,
118+
'isiOSAppOnMac': data.isiOSAppOnMac,
118119
'utsname.sysname:': data.utsname.sysname,
119120
'utsname.nodename:': data.utsname.nodename,
120121
'utsname.release:': data.utsname.release,

packages/device_info_plus/device_info_plus/ios/device_info_plus/Sources/device_info_plus/FPPDeviceInfoPlusPlugin.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
2323

2424
NSNumber *isPhysicalNumber =
2525
[NSNumber numberWithBool:[self isDevicePhysical]];
26+
NSProcessInfo *info = [NSProcessInfo processInfo];
27+
NSNumber *isiOSAppOnMac = [NSNumber numberWithBool:NO];
28+
if (@available(iOS 14.0, *)) {
29+
isiOSAppOnMac = [NSNumber numberWithBool:[info isiOSAppOnMac]];
30+
}
2631
NSString *machine;
2732
if ([self isDevicePhysical]) {
2833
machine = @(un.machine);
2934
} else {
30-
machine = [[NSProcessInfo processInfo]
31-
environment][@"SIMULATOR_MODEL_IDENTIFIER"];
35+
machine = [info environment][@"SIMULATOR_MODEL_IDENTIFIER"];
3236
}
33-
3437
result(@{
3538
@"name" : [device name],
3639
@"systemName" : [device systemName],
@@ -40,6 +43,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
4043
@"identifierForVendor" : [[device identifierForVendor] UUIDString]
4144
?: [NSNull null],
4245
@"isPhysicalDevice" : isPhysicalNumber,
46+
@"isiOSAppOnMac" : isiOSAppOnMac,
4347
@"utsname" : @{
4448
@"sysname" : @(un.sysname),
4549
@"nodename" : @(un.nodename),

packages/device_info_plus/device_info_plus/lib/src/model/ios_device_info.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class IosDeviceInfo extends BaseDeviceInfo {
1818
required this.localizedModel,
1919
this.identifierForVendor,
2020
required this.isPhysicalDevice,
21+
required this.isiOSAppOnMac,
2122
required this.utsname,
2223
}) : super(data);
2324

@@ -52,6 +53,10 @@ class IosDeviceInfo extends BaseDeviceInfo {
5253
/// `false` if the application is running in a simulator, `true` otherwise.
5354
final bool isPhysicalDevice;
5455

56+
/// that indicates whether the process is an iPhone or iPad app running on a Mac.
57+
/// https://developer.apple.com/documentation/foundation/nsprocessinfo/3608556-iosapponmac
58+
final bool isiOSAppOnMac;
59+
5560
/// Operating system information derived from `sys/utsname.h`.
5661
final IosUtsname utsname;
5762

@@ -66,6 +71,7 @@ class IosDeviceInfo extends BaseDeviceInfo {
6671
localizedModel: map['localizedModel'],
6772
identifierForVendor: map['identifierForVendor'],
6873
isPhysicalDevice: map['isPhysicalDevice'],
74+
isiOSAppOnMac: map['isiOSAppOnMac'],
6975
utsname:
7076
IosUtsname._fromMap(map['utsname']?.cast<String, dynamic>() ?? {}),
7177
);

packages/device_info_plus/device_info_plus/test/model/ios_device_info_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void main() {
2020
'utsname': iosUtsnameMap,
2121
'systemName': 'systemName',
2222
'isPhysicalDevice': true,
23+
'isiOSAppOnMac': true,
2324
'systemVersion': 'systemVersion',
2425
'localizedModel': 'localizedModel',
2526
'identifierForVendor': 'identifierForVendor',
@@ -32,6 +33,7 @@ void main() {
3233
expect(iosDeviceInfo.name, 'name');
3334
expect(iosDeviceInfo.model, 'model');
3435
expect(iosDeviceInfo.isPhysicalDevice, isTrue);
36+
expect(iosDeviceInfo.isiOSAppOnMac, isTrue);
3537
expect(iosDeviceInfo.systemName, 'systemName');
3638
expect(iosDeviceInfo.systemVersion, 'systemVersion');
3739
expect(iosDeviceInfo.localizedModel, 'localizedModel');

0 commit comments

Comments
 (0)