I am developing universal IOS app for all devices and IOS 7 and IOS 8. and I have this macros:
This macros is for detecting widescreen iPhone 5, this works for IOS 7:
#define IS_WIDESCREEN_IOS7 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
This macros is also for for widescreen iPone 5, but works only for IOS 8:
#define IS_WIDESCREEN_IOS8 ( fabs( ( double )[ [ UIScreen mainScreen ] nativeBounds ].size.height - ( double )1136 ) < DBL_EPSILON )
I need to combine this code to make it work on both IOS 7 and IOS 8and for that I need selector that detects IOS version., here is the code:
#define IS_WIDESCREEN_IOS7 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
#define IS_WIDESCREEN_IOS8 ( fabs( ( double )[ [ UIScreen mainScreen ] nativeBounds ].size.height - ( double )1136 ) < DBL_EPSILON )
#define IS_WIDESCREEN ( ( [ [ UIScreen mainScreen ] respondsToSelector: @selector( nativeBounds ) ] ) ? IS_WIDESCREEN_IOS8 : IS_WIDESCREEN_IOS7 )
then the author of the post suggests to quote -"If you're also targeting iOS 7 or lower, be sure to use feature detection, as calling nativeBounds prior to iOS 8 will crash your app:" and gives following code:
if( [ [ UIScreen mainScreen ] respondsToSelector: @selector( nativeBounds ) ] )
{
/* Detect using nativeBounds - iOS 8 and greater */
}
else
{
/* Detect using bounds - iOS 7 and lower */
}
Please help me here I am a beginner developer and want to understand to to make it work. Where should I put SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"Background"];?
All this code is from different post in Stackoverflow post here is it: How to detect iPhone 5 (widescreen devices)?
I uploaded images to drop box here is the link https://www.dropbox.com/sh/pnll2e2jvo0uigs/AACOLbzzQqZlJEZZcBx7TMR1a?dl=0 the folder is called measuredImages. here is the code I use for adding background: #import "GameScene.h"
@implementation GameScene
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"Background-568"]; background.anchorPoint = CGPointMake(0.5, 1);
background.position = CGPointMake(self.size.width/2, self.size.height);
[self addChild:background];}
return self;
}
If someone could put full code with macros and usage in answer I would greatly appreciate it.
Important UPDATE:12.17.2014
This problem was solved by including the right launch images and my app run in the right resolution and I used screen bounds [same as in ios7], as Daij-Djan suggested. Thanks to everybody who tried or helped me to solve this problem,I personally want to thank Daij-Djan and sha for help and support. If you need the code for widescreen iphones I will leave it in my own answer below, it runs on all iPhones above iPhone 4 and all iPads.