How to detect iPhone 6 (6 plus) on simulator - ios

I have found this nice defines:
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
But when I run iPhone 6 simulator or iPhone 6 plus simulator it every time work as iPhone 5.
I have checked the screen size:
(lldb) po [UIScreen mainScreen]
<UIScreen: 0x7ffb3a402930; bounds = {{0, 0}, {320, 568}}; mode = <UIScreenMode: 0x7ffb3a520a80; size = 640.000000 x 1136.000000>>
and seems everting is clear why it points me to iPhone 5 instead of iPhone 6 or iPhone 6 plus.

You have to add the appropriate launch images so the app device/simulator starts using the real size and not a zoomed or emulated size, until you add a launch image for Retina HD 5.5 and Retina HD 4.7 you won't be using the new sizes.
Click the small grey arrow on the Launch Images Source in your Project General Settings and add the appropriate launch images.

Related

How can you determine iPhone X Simulator programmatically?

I am trying to size my app for iPhone X and am having trouble.
Currently I define screen sizes like so:
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
and constrain based on the phone type. (Yes i know not optimal but its what ive done)
When you use the iPhone X simulator, for some reason it reads its screen height and width like an iPhone 6.
So then I searched stack overflox and found this:
How to get device make and model on iOS?
Only issue is, when you run on the iPhone X simulator it returns x86-64 and not a device type!
I obviously dont have an iPhone X so how do I detect that this is an iPhone X Simulator and not an iPhone 6 (based on screen size) so I can constrain properly for this new phone!
Thank you people!
func modelIdentifier() -> String {
if let simulatorModelIdentifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] { return simulatorModelIdentifier }
var sysinfo = utsname()
uname(&sysinfo) // ignore return value
return String(bytes: Data(bytes: &sysinfo.machine, count: Int(_SYS_NAMELEN)), encoding: .ascii)!.trimmingCharacters(in: .controlCharacters)
}
from here
Objective-c:
- (NSString *)modelIdentifier {
NSString *simulatorModelIdentifier = [NSProcessInfo processInfo].environment[#"SIMULATOR_MODEL_IDENTIFIER"];
NSLog(#"%#",simulatorModelIdentifier);
if (simulatorModelIdentifier) {
return simulatorModelIdentifier;
}
struct utsname sysInfo;
uname(&sysInfo);
return [NSString stringWithCString:sysInfo.machine encoding:NSUTF8StringEncoding];
}
Don't forget:
#import <sys/utsname.h>
Use: (In viewDidLoad for example):
NSString *model = [self modelIdentifier];
NSLog(#"Device: %#", model);
If model is iPhone10,3, it is a iPhone X.
I don't recommend doing it this way, but if you must, the following code will return "iPhone10,3" or "iPhone10,6" for an iPhoneX.
NSString *GetHardwareName(void)
{
NSString *result = nil;
struct utsname platform;
if ( uname(&platform) == 0 )
{
if ( platform.machine[0] )
result = [NSString stringWithCString:platform.machine encoding:NSUTF8StringEncoding];
}
return result;
}
Hi you can use below micro to check iPhoneX size.
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_4 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 480.0)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0)
#define IS_IPHONE_6PLUS (IS_IPHONE && [[UIScreen mainScreen] nativeScale] == 3.0f)
#define IS_IPHONE_6_PLUS (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0)
#define IS_IPHONE_X (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 812.0)
#define IS_RETINA ([[UIScreen mainScreen] scale] == 2.0)
#define IS_IPAD_DEVICE [(NSString*)[UIDevice currentDevice].model hasPrefix:#"iPad"]

Determine iOS Simulator selected device

Is there a way to programmatically determine which simulated device is being used in the iPhone sim? UIDevice just returns iPhone Simulator, whether I pick iPhone4, 5s, 6, iPad, etc.
For know the current device.
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)

iPad and IPhone screen size definition error. iPad displays iPhone parametrers

At first i was making app for iPad, but then decided to make it universal but after i define screen size, like this :
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
Now on iPad screen size shows up like it was for iPhone, every thing on screen are too small. Is that some kind of bug? or i did something wrong, how can i change it?
iPad display iPhone parameter , the reason is that app screen size becomes zoom to fit on iPad screen, but actually it capturing iPhone screen size only.
To resolve this you need to make your app as Universal. In Xcode->Target->General->Deployment Info->Device Select Universal.

Display Splash image according to iPhone size

if([UIScreen mainScreen].bounds.size.height==667)
{
animatedSplashScreen.animationImages= [NSArray arrayWithObjects:[UIImage imageNamed:#"i4.png"],nil]; }
if([UIScreen mainScreen].bounds.size.height==736)
{
animatedSplashScreen.animationImages= [NSArray arrayWithObjects:[UIImage imageNamed:#"i2.png"],nil]; }
if([UIScreen mainScreen].bounds.size.height==568)
{
animatedSplashScreen.animationImages= [NSArray arrayWithObjects:[UIImage imageNamed:#"i5.png"],nil];
}
I don't understand why you are not using Asset Catalog. It is a very easy procedure through which you can add icons and splash in asset catalog.
Referred from this.
Alternative way, if you have do it programmatically, then you can put the check of iPhone screen size by these following macro- :
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
You can use LauchScreen.xib. Put an Image view as of xib's main view size. Use autolayout to pin it with all four side.
ie. 1.Trailing space to superView
2.Leading space to superView
3.Bottom space to superView
4.Top sapace to superView

iphone 6+ real device on landscape view is not working

An user reported that the iOS app on an iPhone 6+, the landscape view is not working.
I don't have a real iPhone 6+ to test it, but on the simulator it works fine. Any thoughts?
The problem was that I was using some #define code asking if the device was iPhone6+, and the code wasn't working as expected. So I changed the code to be like this:
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_6_PLUS (IS_IPHONE && IS_OS_8_OR_LATER && SCREEN_MAX_LENGTH == 736.0)

Resources