Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Sep 7, 2021. It is now read-only.

Commit 0fc533e

Browse filesBrowse files
Merge pull request livecode#7457 from livecodepanos/iphone_get_device_model
[[ Bug 21769 ]] Add new function iphoneDeviceModel()
2 parents 49a5442 + 85f29c7 commit 0fc533e
Copy full SHA for 0fc533e

File tree

Expand file treeCollapse file tree

11 files changed

+73
-69
lines changed
Filter options
Expand file treeCollapse file tree

11 files changed

+73
-69
lines changed
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Name: iphoneDeviceModel
2+
3+
Type: function
4+
5+
Syntax: iphoneDeviceModel()
6+
7+
Summary:
8+
Returns the machine name of the device the app is running on
9+
10+
11+
Introduced: 9.6.3
12+
13+
OS: ios
14+
15+
Platforms: mobile
16+
17+
Example:
18+
local tModel
19+
put iphoneDeviceModel() into tModel
20+
21+
22+
Description:
23+
Use the <iphoneDeviceModel> function to get the machine name of the device the app is running on
24+
25+
Note: The machine name is different from the full readable name of the device.
26+
You can find a mapping between these two names here: http://theiphonewiki.com/wiki/Models
27+
28+
29+

‎docs/notes/bugfix-21769.md

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Added new function iphoneDeviceModel() that returns the machine name of the iOS device the app is running on

‎engine/src/exec-misc.cpp

Copy file name to clipboardExpand all lines: engine/src/exec-misc.cpp
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ void MCMiscExecVibrate(MCExecContext& ctxt, int32_t* p_number_of_times)
117117
ctxt.Throw();
118118
}
119119

120+
void MCMiscGetDeviceModel(MCExecContext& ctxt, MCStringRef& r_model)
121+
{
122+
if(MCSystemGetDeviceModel(r_model))
123+
return;
124+
125+
ctxt.Throw();
126+
}
127+
120128
void MCMiscGetDeviceResolution(MCExecContext& ctxt, MCStringRef& r_resolution)
121129
{
122130
if(MCSystemGetDeviceResolution(r_resolution))

‎engine/src/exec.h

Copy file name to clipboardExpand all lines: engine/src/exec.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4017,6 +4017,7 @@ void MCMiscGetLaunchData(MCExecContext &ctxt, MCArrayRef &r_data);
40174017
void MCMiscExecBeep(MCExecContext& ctxt, int32_t* p_number_of_times);
40184018
void MCMiscExecVibrate(MCExecContext& ctxt, int32_t* p_number_of_times);
40194019

4020+
void MCMiscGetDeviceModel(MCExecContext& ctxt, MCStringRef& r_model);
40204021
void MCMiscGetDeviceResolution(MCExecContext& ctxt, MCStringRef& r_resolution);
40214022
void MCMiscSetUseDeviceResolution(MCExecContext& ctxt, bool p_use_device_res, bool p_use_control_device_res);
40224023
void MCMiscGetDeviceScale(MCExecContext& ctxt, real64_t& r_scale);

‎engine/src/mblandroidmisc.cpp

Copy file name to clipboardExpand all lines: engine/src/mblandroidmisc.cpp
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,12 @@ bool MCSystemGetPixelDensity(real64_t& r_density)
655655

656656
////////////////////////////////////////////////////////////////////////////////
657657

658+
bool MCSystemGetDeviceModel(MCStringRef& p_model)
659+
{
660+
// Not implemented
661+
return false;
662+
}
663+
658664
bool MCSystemGetDeviceResolution(MCStringRef& p_resolution)
659665
{
660666
// Not implemented

‎engine/src/mblhandlers.cpp

Copy file name to clipboardExpand all lines: engine/src/mblhandlers.cpp
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,6 +2840,23 @@ Exec_stat MCHandleVibrate(void *p_context, MCParameter *p_parameters)
28402840
return ES_ERROR;
28412841
}
28422842

2843+
Exec_stat MCHandleDeviceModel(void *context, MCParameter *p_parameters)
2844+
{
2845+
MCExecContext ctxt(nil, nil, nil);
2846+
2847+
MCAutoStringRef t_device_model;
2848+
MCMiscGetDeviceModel(ctxt, &t_device_model);
2849+
2850+
if (!ctxt.HasError())
2851+
{
2852+
ctxt.SetTheResultToValue(*t_device_model);
2853+
return ES_NORMAL;
2854+
}
2855+
2856+
ctxt.SetTheResultToEmpty();
2857+
return ES_ERROR;
2858+
}
2859+
28432860
Exec_stat MCHandleDeviceResolution(void *context, MCParameter *p_parameters)
28442861
{
28452862
MCExecContext ctxt(nil, nil, nil);
@@ -4707,6 +4724,7 @@ static const MCPlatformMessageSpec s_platform_messages[] =
47074724
{false, "mobileSetKeyboardType", MCHandleSetKeyboardType, nil},
47084725
{false, "mobileSetKeyboardReturnKey", MCHandleSetKeyboardReturnKey, nil}, // Added from androidmisc.cpp
47094726

4727+
{false, "iphoneDeviceModel", MCHandleDeviceModel, nil},
47104728
{false, "iphoneDeviceResolution", MCHandleDeviceResolution, nil},
47114729
{false, "iphoneUseDeviceResolution", MCHandleUseDeviceResolution, nil},
47124730
{false, "iphoneDeviceScale", MCHandleDeviceScale, nil},

‎engine/src/mbliphoneapp.mm

Copy file name to clipboardExpand all lines: engine/src/mbliphoneapp.mm
+1-60Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,66 +1706,7 @@ - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
17061706

17071707
NSString *t_machine_name = [NSString stringWithCString:t_system_info.machine encoding:NSUTF8StringEncoding];
17081708

1709-
// MARK: We can just return t_machine_name. Following is for convenience
1710-
// Full list at http://theiphonewiki.com/wiki/Models
1711-
1712-
NSDictionary *commonNamesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
1713-
@"iPhone", @"iPhone1,1",
1714-
@"iPhone 3G", @"iPhone1,2",
1715-
@"iPhone 3GS", @"iPhone2,1",
1716-
@"iPhone 4", @"iPhone3,1",
1717-
1718-
@"iPhone 4(Rev A)", @"iPhone3,2",
1719-
@"iPhone 4(CDMA)", @"iPhone3,3",
1720-
@"iPhone 4S", @"iPhone4,1",
1721-
@"iPhone 5(GSM)", @"iPhone5,1",
1722-
@"iPhone 5(GSM+CDMA)", @"iPhone5,2",
1723-
@"iPhone 5c(GSM)", @"iPhone5,3",
1724-
@"iPhone 5c(GSM+CDMA)", @"iPhone5,4",
1725-
@"iPhone 5s(GSM)", @"iPhone6,1",
1726-
@"iPhone 5s(GSM+CDMA)", @"iPhone6,2",
1727-
1728-
@"iPhone 6+ (GSM+CDMA)", @"iPhone7,1",
1729-
@"iPhone 6 (GSM+CDMA)", @"iPhone7,2",
1730-
1731-
@"iPad", @"iPad1,1",
1732-
@"iPad 2(WiFi)", @"iPad2,1",
1733-
@"iPad 2(GSM)", @"iPad2,2",
1734-
@"iPad 2(CDMA)", @"iPad2,3",
1735-
@"iPad 2(WiFi Rev A)", @"iPad2,4",
1736-
@"iPad Mini 1G (WiFi)", @"iPad2,5",
1737-
@"iPad Mini 1G (GSM)", @"iPad2,6",
1738-
@"iPad Mini 1G (GSM+CDMA)", @"iPad2,7",
1739-
@"iPad 3(WiFi)", @"iPad3,1",
1740-
@"iPad 3(GSM+CDMA)", @"iPad3,2",
1741-
@"iPad 3(GSM)", @"iPad3,3",
1742-
@"iPad 4(WiFi)", @"iPad3,4",
1743-
@"iPad 4(GSM)", @"iPad3,5",
1744-
@"iPad 4(GSM+CDMA)", @"iPad3,6",
1745-
1746-
@"iPad Air(WiFi)", @"iPad4,1",
1747-
@"iPad Air(GSM)", @"iPad4,2",
1748-
@"iPad Air(GSM+CDMA)", @"iPad4,3",
1749-
1750-
@"iPad Mini 2G (WiFi)", @"iPad4,4",
1751-
@"iPad Mini 2G (GSM)", @"iPad4,5",
1752-
@"iPad Mini 2G (GSM+CDMA)", @"iPad4,6",
1753-
1754-
@"iPod 1st Gen", @"iPod1,1",
1755-
@"iPod 2nd Gen", @"iPod2,1",
1756-
@"iPod 3rd Gen", @"iPod3,1",
1757-
@"iPod 4th Gen", @"iPod4,1",
1758-
@"iPod 5th Gen", @"iPod5,1",
1759-
// PM-2015-03-03: [[ Bug 14689 ]] Cast to NSString* to prevent EXC_BAD_ACCESS when in release mode and run in 64bit device/sim
1760-
(NSString *)nil];
1761-
1762-
1763-
NSString *t_device_name = [commonNamesDictionary objectForKey: t_machine_name];
1764-
1765-
if (t_device_name == nil)
1766-
t_device_name = t_machine_name;
1767-
1768-
return t_device_name;
1709+
return t_machine_name;
17691710
}
17701711

17711712
MCIPhoneApplication *MCIPhoneGetApplication(void)

‎engine/src/mbliphoneextra.mm

Copy file name to clipboardExpand all lines: engine/src/mbliphoneextra.mm
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,13 @@ bool MCSystemVibrate (int32_t p_number_of_vibrates)
581581

582582
/////////////////////////////////////////////////////////////////////////////////////////////////////
583583

584+
bool MCSystemGetDeviceModel(MCStringRef& r_model)
585+
{
586+
NSString *t_device_model_name = MCIPhoneGetDeviceModelName();
587+
588+
return MCStringCreateWithCFStringRef((CFStringRef)t_device_model_name, r_model);
589+
}
590+
584591
bool MCSystemGetDeviceResolution(MCStringRef& p_resolution)
585592
{
586593
UIScreenMode *t_mode;

‎engine/src/mbliphonepick.mm

Copy file name to clipboardExpand all lines: engine/src/mbliphonepick.mm
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,6 @@ - (void) startPicking: (NSArray *)p_pickerOptions andInitial: (NSArray *)p_initi
505505
m_bar_visible = true;
506506
}
507507

508-
// PM-2014-10-22: [[ Bug 13750 ]] Make sure the view under the pickerView is not visible (iphone 4 only)
509-
NSString *t_device_model_name = MCIPhoneGetDeviceModelName();
510-
if ([t_device_model_name isEqualToString:@"iPhone 4"] || [t_device_model_name isEqualToString:@"iPhone 4(Rev A)"] || [t_device_model_name isEqualToString:@"iPhone 4(CDMA)"])
511-
pickerView.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.90];
512-
513508
// set the label item
514509
for (t_i = 0; t_i < [m_selected_index count]; t_i++)
515510
[pickerView selectRow:[[m_selected_index objectAtIndex:t_i] integerValue] inComponent:t_i animated:NO];

‎engine/src/mbliphonepickdate.mm

Copy file name to clipboardExpand all lines: engine/src/mbliphonepickdate.mm
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,13 @@ - (void) startDatePicker:(NSString *)p_style andCurrent: (int32_t)r_current andS
251251
[datePicker setLocale:t_locale];
252252
[datePicker setCalendar:[t_locale objectForKey:NSLocaleCalendar]];
253253
[datePicker setTimeZone:[NSTimeZone localTimeZone]];
254+
254255
#ifdef __IPHONE_14_0
255256
if (@available(iOS 14, *))
256257
{
257258
[datePicker setPreferredDatePickerStyle: UIDatePickerStyleWheels];
258259
}
259260
#endif
260-
// PM-2014-10-22: [[ Bug 13750 ]] Make sure the view under the pickerView is not visible (iphone 4 only)
261-
NSString *t_device_model_name = MCIPhoneGetDeviceModelName();
262-
if ([t_device_model_name isEqualToString:@"iPhone 4"] || [t_device_model_name isEqualToString:@"iPhone 4(Rev A)"] || [t_device_model_name isEqualToString:@"iPhone 4(CDMA)"])
263-
datePicker.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.90];
264261

265262
// set up the style and parameters for the date picker
266263
if (p_style == nil || MCCStringEqual([p_style cStringUsingEncoding:NSMacOSRomanStringEncoding], "dateTime"))

‎engine/src/mblsyntax.h

Copy file name to clipboardExpand all lines: engine/src/mblsyntax.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ bool MCSystemGetLaunchData(MCArrayRef &r_lauch_data);
432432
bool MCSystemBeep(int32_t p_number_of_times);
433433
bool MCSystemVibrate(int32_t p_number_of_times);
434434

435+
bool MCSystemGetDeviceModel(MCStringRef& r_model);
435436
bool MCSystemGetDeviceResolution(MCStringRef& p_resolution);
436437
bool MCSystemGetPixelDensity(real64_t& r_density);
437438
bool MCSystemSetDeviceUseResolution(bool p_use_device_res, bool p_use_control_device_res);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.