Detect iPhone specific application 'is running' on iPAD - ios

I have an app which is developed for iPhone only. When user runs it on iPAD
it is not showing properly. I know how to detect "IS_iPAD" when project is universal but
when project is iPhone specific the USER DEVICE is always returned as iPhone.
How one can detect if iPhone specific application is run on iPAD?

For sake of completion here is the #MichaelPatzer answer pointed by #user42949
If the app is an iPhone app running in the emulator mode on an iPad,
it will have a userInterfaceIdiom of Phone, but a model type of iPad.
You can check this with the following code:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
[[[UIDevice currentDevice] model] hasPrefix:#"iPad"]) {
// This app is an iPhone app running on an iPad
}

You can use this different macro to know if you are using iPhone, iPhone 5 or iPad :
#define IS_IPHONE() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPAD() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE5() ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) && [UIScreen mainScreen].bounds.size.height == 568)

Another option, if your code is layout-specific (which is how I got here):
CGSize screenSize = [UIScreen mainScreen].bounds.size;
CGFloat screenRatio = MIN(screenSize.width / screenSize.height, screenSize.height / screenSize.width); // account for rotation
if(screenRatio > 6.65 && screenRatio < 6.67) {
// iPad is 6.66666
}

Related

How to rotate a photo on iPhone only?

I have an iPhone app I am testing on my iPhone and iPad. When running my app adhoc, the problem is that when the photo loads on my iPhone 4 during ad hoc testing, the photo loads on its side; the photo loads fine on iPad mini.
The following line of code successfully rotates the fullscreen image on iPhone, but conversely rotates the image when I test on iPad.
//successfully rotates but also over rotates on iPad
PhotoView.transform=CGAffineTransformMakeRotation(M_PI*0.5);
Can someone help me set up conditional statements so I can use my CGAffineTransforMakeRotation line of code only on iPad?
I have so far tried the following conditional statements but they don't work for some reason: i.e. only the iPhone if statement works and overrides the iPad if statement so the iPhone statement is carried out on both devices.
//does not successfully set the bk for iPad but does for iPhone. The iPad statement is overridden and the iPhone statement is carried out on both platforms. Any ideas?
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
}
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
}
This second conditional statement also doesn't work...
if ([[UIScreen mainScreen] bounds].size.height == 480)
{
// iPhone, iPod Touch
}
if ([[UIScreen mainScreen] bounds].size.height == 568) {
// iPhone 5
}
if ([[UIScreen mainScreen] bounds].size.height == 667) {
// iP6
}
if ([[UIScreen mainScreen] bounds].size.height == 736) {
// iP6+
}
if ([[UIScreen mainScreen] bounds].size.height == 1024) {
// iPad
}
My question: does anyone have code to rotate an image on iPhone but not iPad?
If it's an iPhone app, it is always "on an iPhone". Even when running on the iPad, it is running on a virtual iPhone in emulation mode. It is impossible for it to behave differently on the different devices; it is running on just one device type, as far as it can tell.
If you don't like that, make it a Universal app. Now it runs natively on iPad and your tests will work.

xcode when i run program on iphone 5 screen looks iphone 4

I'm using Xcode 6 and use objective-c when i test program on iOS 8 (iPhone 5) program run without error but when i try to test program on iOS 7 (iPhone 5) screen look like iPhone 4 screen. I can detect phone like this;
#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 736)
#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 667)
#define IS_IPHONE_5 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568)
#define IS_IPAD UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
and also i can detect operating system like this;
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_0)
{
#define IS_IPHONE_5 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568)
}
When i do this screen not scale on phone because when i run on iOS 7 phone screen run like iPhone 4 check image for more description.
As you can see top and bottom black.How can i fix this problem
Set an iPhone 5 launch screen. It will be fixed.
iPhone 5 launch screen spec: 640x1136
For the time being create a blank screen on photoshop or preview. You can replace it later.

Having issue with detect iPhone 6/Plus on simulator

I am trying to build a version of my app specifically for iPhone 6 and 6 Plus , whereas I don't have any hardware , I have to test on the simulator ! but it seems , simulator has a strange bug ! first and for most I get screen resolutions and scales , by this code :
UIScreen *mainScreen = [UIScreen mainScreen];
NSLog(#"Screen bounds: %#, Screen resolution: %#, scale: %f, nativeScale: %f",
NSStringFromCGRect(mainScreen.bounds), mainScreen.coordinateSpace, mainScreen.scale, mainScreen.nativeScale);
so here is how detect iPhone 6 and 6Plus (Portrait mode):
#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 667)
#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 736)
the problem is ! when I lunch my app on iPhone6/Plus simulator , compiler gives me the sceen information of iPhone 4" display :
2014-09-28 12:32:08.153 WOD[2924:42290]
Screen bounds: {{0, 0}, {320, 568}}, Screen resolution: <UIScreen: 0x7fa15be0f9b0; bounds = {{0, 0}, {320, 568}}; mode = <UIScreenMode: 0x7fa15bd0d4a0;
size = 640.000000 x 1136.000000>>, scale: 2.000000, nativeScale: 2.000000
But it works fine on new project ! (I cannot create a new project and start over again !).
I cleaned code , delete build folder , change project's name ,and reset Simulator contents setting but still gives me the information of 4" display ! .
I have checked this Q/A but answers require a real device !
The main reason I faced with this problem was I build my application with Xcode 5 and open it with Xcode 6
Solution :
Add Launch Image for Retina HD 5.5 and 4.7 :
Now you can detect iPhone 6/Plus on simulator without having a real device :
#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 667)
#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 736)
Just in case you need to detect iPhone 6/6Plus in landscape, use this.
#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 667)
#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 736)

How can I check what iOS device the user is using? [duplicate]

This question already has answers here:
Detect iOS device type
(5 answers)
Identify new iPhone model on xcode (5, 5c, 5s) [duplicate]
(6 answers)
Closed 9 years ago.
How can I find out what device a user is using? The code I currently use is:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if(screenBounds.size.height == 568){
NSLog(#"User is using an iPhone 5s, 5c, or 5");
}
else{
NSLog(#"User is using an iPhone 4s or earlier");
}
What other numbers could this return, and what device would it be? For example, I was hoping for something like this:
screenBounds.size.height == 568 would be an iPhone5/5s/5c
screenBounds.size.height == 480 would be an iPhone 4/5s
screenBounds.size.height > 570 would be an iPad
and so on. I'm going to be using this to change the nib file based on what device the user is using, so that I won't have to move every single button, image, label, or anything else with CGRectMake.
I'm not using auto layout because I would also like to have some more customization based on what device the user is using.
To check the kind of device:
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
// You are using iPad
return YES;
}
else if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomiPhone )
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if(screenBounds.size.height == 568){
NSLog(#"User is using an iPhone 5+");
} else{
NSLog(#"User is using an iPhone 4s-");
}
}

How to detect if the device is an iPhone 5? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to detect iPhone 5 (widescreen devices)?
I am trying to add a new view to an existing ios4 project to handle the new iphone5 screen size.
However I dont have an iphone here to test on and the code I am using to test the screen size isnt working, just wondering if there is another way of detecting the device type??
NSLog(#"%f", [ [ UIScreen mainScreen ] bounds ].size.height);
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
if([UIScreen mainScreen].bounds.size.height == 568.0)
{
//move to your iphone5 storyboard
[self changeView:splashScreenBIGV viewH:splashScreenH animLength:SCREEN_CHANGE_ANIM_LENGTH];
}
else{
//move to your iphone4s storyboard
[self changeView:splashScreenV viewH:splashScreenH animLength:SCREEN_CHANGE_ANIM_LENGTH];
}
}
For my universal app, Forex App, I'm simply using the screen height detection concept like so:
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if (screenSize.height > 480.0f) {
/*Do iPhone 5 stuff here.*/
} else {
/*Do iPhone Classic stuff here.*/
}
} else {
/*Do iPad stuff here.*/
}
Answer is here. Basically, you don't. Use the new constraint layout system in iOS 6. You'll be chasing your tail if you have to rev your layout for every new device with a different screen size/resolution.

Resources