-2

I am developing universal game for all iPhone 4 and higher and for all iPads, I want it work for IOS 7 and 8. I have tried a lot of macros but never they work ether for all devices or IOS 7 and 8.I am a beginner developer and I dont know how to solve this problem. I uploaded images to dropbox and you can get them at this link here https://www.dropbox.com/sh/pnll2e2jvo0uigs/AACOLbzzQqZlJEZZcBx7TMR1a?dl=0

here is the code I am using for my SpriteKit game to add background to the scene:

#import "GameScene.h"
#import <UIKit/UIKit.h>

#define IS_WIDESCREEN (( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON ) || ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.width - ( double )568 ) < DBL_EPSILON ))

@implementation GameScene


-(id)initWithSize:(CGSize)size {
    if (self = [super initWithSize:size]) {
        SKSpriteNode*background;

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
            if (IS_WIDESCREEN){
                background = [SKSpriteNode spriteNodeWithImageNamed:@"Background-568"];
            }else{
                 background = [SKSpriteNode spriteNodeWithImageNamed:@"Background"];
            }

        }else{ 
            background = [SKSpriteNode spriteNodeWithImageNamed:@"Background~iPad"];
        }

        background.anchorPoint = CGPointMake(0.5, 1);
        background.position = CGPointMake(self.size.width/2, self.size.height);
        //background.zPosition = LayerBackground;
        [self addChild:background];
    }

    return self;
}

@end

I would much appreciate if you could help me to solve this problem and give me the code in answer you post, like what macros to put and usage of it. also use my code for background and images uploaded to dropbox. Thanks a lot.

jproffitt
  • 6,225
  • 30
  • 42
  • How is this different from your previous question (http://stackoverflow.com/questions/27496178/how-to-detect-ios-7-and-ios-8-for-universal-app)? – rmaddy Dec 17 '14 at 02:18
  • this one have easier to work with. You can download images and try them with your macros and if your answer is correct then you can help me by posting code and usage of it. – David Muldarov Dec 17 '14 at 02:44

2 Answers2

2

Ref to SDiPhoneVersion to detect the device info.

Check IOS version:

iOSVersionEqualTo(@"7.0")  // ios version = 7.0
iOSVersionGreaterThan(@"7.0"))  // ios version > 7.0
iOSVersionGreaterThanOrEqualTo(@"7.0") )  // ios version >= 7.0
iOSVersionLessThan(@"7.0"))  // ios version < 7.0
iOSVersionLessThanOrEqualTo(@"7.0")   )  // ios version <= 7.0

Targetable screen sizes

  • iPhone35inch
  • iPhone4inch
  • iPhone47inch
  • iPhone55inch

    DeviceSize size = [SDiPhoneVersion deviceSize] ;
    if(size == iPhone35inch){
        // iphone4 to do
    }else if(size == iPhone4inch){
        // iphone5s to do
    
    }else if(size == iPhone47inch){
        // iphone6 to do
    
    }else if(size == iPhone55inch){
        // iphone6 plus to do
    
    }
    

Besides you can define some macros to detect some other info

Check device type

#define Device                     [UIDevice currentDevice]
#define IS_iPhone_Device           (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_iPhone_Simulator        [Device.model isEqualToString:@"iPhone Simulator"]
#define IS_iPhone                  (IS_iPhone_Device || IS_iPhone_Simulator)
#define IS_iPad_Device             (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_iPad_Simulator          [Device.model isEqualToString:@"iPad Simulator"]
#define IS_iPad                    (IS_iPad_Device || IS_iPad_Simulator)

Check device orientation

#define Application                [UIApplication sharedApplication]
#define IS_PortriatOrientation     UIInterfaceOrientationIsPortrait(Application.statusBarOrientation)
#define IS_LandscapeOrientation    UIInterfaceOrientationIsLandscape(Application.statusBarOrientation)

#define IS_LandscapeOrientation_HomeLeft  (Application.statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
#define IS_LandscapeOrientation_HomeRight (Application.statusBarOrientation == UIInterfaceOrientationLandscapeRight)
#define IS_PortriatOrientation_HomeBottom (Application.statusBarOrientation == UIInterfaceOrientationPortrait)
#define IS_PortriatOrientation_HomeTop    (Application.statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)

It may help you .

monjer
  • 2,809
  • 2
  • 21
  • 31
  • Please could edit your answer and integrate my background method to it so I can try it? I really dont know where to put what, that is why I am having hard time to solve this problem. – David Muldarov Dec 17 '14 at 02:50
1

For example, I use this code to check for the device's screen:

//Getting iDevice's screen width
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
Richard Topchii
  • 7,075
  • 8
  • 48
  • 115