iOS Question Detect if iphone or ipad

IDDGroup

Member
Licensed User
Longtime User
Is there a way in B4I to tell if you are on an ipad or an iphone?

I need to have different screens depending on the device type (IE: I can fit more on an ipad screen, phone has to be broken into multiple screens)

--Karl
 
iPads are usually having a 4:3 aspect ratio so

B4X:
if 100%x / 100%y < 1.35 then 'it's an iPad.

you could compare with 1.77 aswell which is 16:9 (iphones) as they seem to have other ratios for the new ipad.
 
Upvote 0
There's got to be a way to get the device namesomehow.

I tried
B4X:
    Dim no As NativeObject = Me
    Log(no.RunMethod("deviceName", Null).AsString)

as i found on the forums, but the method "deviceName" is not valid.
 
Upvote 0
Add
Code:
#If OBJC

#import <sys/utsname.h>

- (NSString*) deviceName {
  struct utsname systemInfo;
  uname (&systemInfo);
  return [NSString stringWithCString: systemInfo.machine encoding:NSUTF8StringEncoding];
  }

#end if
 
Upvote 0
That worked.

also, as sorex mentioned, you can check if less than 1.5 (ipad 11 is 1.43 ratio, all phones are higher, all other ipads are 1.33)
 
Upvote 0
For a more exact answer, take a look at this post:
 
Upvote 0
iPads are usually having a 4:3 aspect ratio so

B4X:
if 100%x / 100%y < 1.35 then 'it's an iPad.

you could compare with 1.77 aswell which is 16:9 (iphones) as they seem to have other ratios for the new ipad.

Just a correction here ... the ratio should be the other way around:

B4X:
if 100%y / 100%x < 1.35 then 'it's an iPad.
 
Upvote 0
Back
Top