Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(device_info_plus)!: return type of isPhysicalDevice as boolean for ios #2508

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
struct utsname un;
uname(&un);

NSNumber *isPhysicalNumber =
[NSNumber numberWithBool:[self isDevicePhysical]];
Comment on lines +24 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Objective-C is weird :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was my first time writing code in Objective-C, from a Java and Android background. Undoubtedly, it was horrible for me.

NSString *machine;
if ([[self isDevicePhysical] isEqualToString:@"true"]) {
if ([self isDevicePhysical]) {
machine = @(un.machine);
} else {
machine = [[NSProcessInfo processInfo]
Expand All @@ -37,7 +39,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
@"localizedModel" : [device localizedModel],
@"identifierForVendor" : [[device identifierForVendor] UUIDString]
?: [NSNull null],
@"isPhysicalDevice" : [self isDevicePhysical],
@"isPhysicalDevice" : isPhysicalNumber,
@"utsname" : @{
@"sysname" : @(un.sysname),
@"nodename" : @(un.nodename),
Expand All @@ -52,11 +54,12 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
}

// return value is false if code is run on a simulator
- (NSString *)isDevicePhysical {
- (BOOL)isDevicePhysical {
BOOL isPhysicalDevice = NO;
#if TARGET_OS_SIMULATOR
NSString *isPhysicalDevice = @"false";
isPhysicalDevice = NO;
#else
NSString *isPhysicalDevice = @"true";
isPhysicalDevice = YES;
#endif

return isPhysicalDevice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class IosDeviceInfo extends BaseDeviceInfo {
model: map['model'],
localizedModel: map['localizedModel'],
identifierForVendor: map['identifierForVendor'],
isPhysicalDevice: map['isPhysicalDevice'] == 'true',
isPhysicalDevice: map['isPhysicalDevice'],
utsname:
IosUtsname._fromMap(map['utsname']?.cast<String, dynamic>() ?? {}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void main() {
'model': 'model',
'utsname': iosUtsnameMap,
'systemName': 'systemName',
'isPhysicalDevice': 'true',
'isPhysicalDevice': true,
'systemVersion': 'systemVersion',
'localizedModel': 'localizedModel',
'identifierForVendor': 'identifierForVendor',
Expand Down
Loading