Skip to content
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
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2024, Gluon
* Copyright (c) 2016, 2026, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -56,7 +56,7 @@ static Optional<DeviceService> create() {
}

/**
* Returns the name of the device's model or product. The value is set by the device
* Returns the name of the device's model identifier or product. The value is set by the device
* manufacturer and may be different across versions of the same product.
*
* @return The device model.
Expand Down
40 changes: 36 additions & 4 deletions modules/device/src/main/native/ios/Device.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2024, Gluon
* Copyright (c) 2016, 2026, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -26,9 +26,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import <UIKit/UIKit.h>
#import <sys/utsname.h>
#include "jni.h"
#include "AttachMacros.h"

@interface Device : NSObject {}
- (NSString *)GetDeviceModel;
@end

JNIEnv *env;

JNIEXPORT jint JNICALL
Expand All @@ -46,6 +51,7 @@
}

static int deviceInited = 0;
Device *_device;

// Device
jclass mat_jDeviceServiceClass;
Expand All @@ -59,13 +65,14 @@
return;
}
deviceInited = 1;

_device = [[Device alloc] init];

mat_jDeviceServiceClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "com/gluonhq/attach/device/impl/IOSDeviceService"));
mat_jDeviceService_sendDevice = (*env)->GetStaticMethodID(env, mat_jDeviceServiceClass, "sendDeviceData", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");

UIDevice* currentDevice = [UIDevice currentDevice];

NSString *deviceModel = (NSString*)[currentDevice model];
NSString *deviceModel = [NSString stringWithFormat:@"%@ (%@)", [_device GetDeviceModel], (NSString*)[currentDevice model]];
const char *modelChars = [deviceModel UTF8String];
jstring argModel = (*env)->NewStringUTF(env, modelChars);

Expand All @@ -92,4 +99,29 @@
(*env)->DeleteLocalRef(env, argPlatform);
(*env)->DeleteLocalRef(env, argVersion);
(*env)->DeleteLocalRef(env, argLocale);
}
}

@implementation Device

- (NSString *)GetDeviceModel
{
static dispatch_once_t token;
static NSString *modelString = nil;

dispatch_once(&token, ^{
#if TARGET_OS_SIMULATOR
modelString = [NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"] retain];
#endif
if (modelString == nil) {
struct utsname systemInfo;
uname(&systemInfo);
modelString = [[NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding] retain];
}
});
if (debugAttach) {
AttachLog(@"Device model identifier: %@", modelString);
}
return modelString;
}

@end
Loading