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)
Related
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.
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.
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
}
I have developed an app on the 3.5 inch Screen and now I did a new Storyboard for the 4 inch screen and I do like follows to switch between storyboards on the appdelegate and I logged the screen height and it gives me 480.00000 check it:
NSLog(#"Checking Screen Size");
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
NSLog(#"On iPhone");
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if (iOSDeviceScreenSize.height == 480)
{ (diagonally measured)
NSLog(#"iPhone 4: %f", iOSDeviceScreenSize.height);
}
if (iOSDeviceScreenSize.height == 568)
{
NSLog(#"iPhone 5: %f", iOSDeviceScreenSize.height);
}
The NSLog gives me 480.0000 while my phone is iPhone 5
You need to add a "tall" startup image Default-568h#2x.png to the app to indicate that you support the new display size, otherwise you'll be run in compatibility mode (and not full screen).
You should add a new default image Default-568h#2x.png to the project.
It's very simple, just add Default-568h#2x.png which is Default image for iPhone 5 to the project.
What is the new naming convention for images for the 4-inch retina display?
For an image named background.png you add #2x to the name (background#2x.png) to tell iOS to use that one for devices with the retina display.
What would the suffix be for iPhone 5's screen size?
You can use my #defines to help you with these images:
#define isPhone568 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568)
#define iPhone568ImageNamed(image) (isPhone568 ? [NSString stringWithFormat:#"%#-568h.%#", [image stringByDeletingPathExtension], [image pathExtension]] : image)
#define iPhone568Image(image) ([UIImage imageNamed:iPhone568ImageNamed(image)])
Just give your images the -568h#2x.png notation, and use iPhone568ImageNamed to get a name for standard name or iPhone 5/new iPod.
Usage example from the comments:
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:iPhone568ImageNamed(#"mainscreen.png")]];