Can you iOS App tell which iPhone its running on?

I see how you can change the iPhone model in the build settings. (It looks a little different than in the documentation but essentially works fine). But how can your app know which iPhone Model is running?

I expected to do something like
if TargetIphoneX then …
if TargetIphone8Plus then …

Or do you create a new View for each model?

Most of my views work the same on iPhone and iPad due to auto layout however I have maybe a half-dozen views which are optimised for iPad so, in those cases, I just check if the device is an iPad and then show the iPad-optimised view. There’s code on this forum for detecting whether the device is an iPad or not and there’s other code for returning the exact device model which you can use if you want to be even more granular about it.

The Size method of iOSView might work for you.

Thanks.

How do you check if the device is an iPad? Can you further check if its an iPhone X or iPhone 8 +?

When I search this forum, 250 items will come up. It seems to inherently do an “or”. So a search like “iOS Screensize” might bring up everything for each of iOS and Screensize. Is there some way to make “AND”?

You could do a Select Case on the screen width to determine the various devices. The ‘resolution’ values are here:

http://iosres.com

Or something as simple as this:

If Self.ParentSplitView <> Nil Then 'iPad

Maybe someone can convert this Objective C code to Xojo Declares?

[code]#include <sys/sysctl.h>

  • (NSString *)hardwareVersion {
    size_t size;
    sysctlbyname(“hw.machine”, NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname(“hw.machine”, machine, &size, NULL, 0);
    NSString *strHWMachine = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
    free(machine);
    return strHWMachine;
    }
    [/code]
    This returns e.g. “iPhone10,3” or “iPhone10,6” - and you know that it’s an iPhone X.
    A list of model strings is available here: https://www.theiphonewiki.com/wiki/Models

Edit: I’ve just found the forum post - @Ulrich Bogun has done that already.