How do I restrict my app for only iPhone 6 and 6 Plus?

大兔子大兔子 提交于 2019-12-10 03:09:06

问题


CONTEXT

I'm developing a Crossword game app that currently runs on iPad devices. Apple has recently released iPhone 6 and iPhone 6+ devices, which fortunately have a bigger screen and thus become eligibly to run my game (I have tested my game on a iPhone 5S device and if found that it was not pleasant to the user to run in such screen size).

In this way, I decided to migrate my app to an Universal binary that would include support for iPhone 6, iPhone 6 Plus and iPad devices.

QUESTION

  1. Is there any way to restrict my iOS app to run only on iPhone 6 and iPhone 6+ devices?

Or, at least:

  1. Is there any way to restrict my iOS app to run only on iPhone 6+ devices?

回答1:


I know it's probably way too late, and probably doesn't answer the question anyway, but I figured 'what the heck' – it's a nice bit of code to determine ranges of devices, where in cases you may want different functionality.

#import <sys/sysctl.h>

-(BOOL)isANewerDevice{

    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
    free(machine);

    NSString * ending = [platform substringFromIndex:[platform length]-3];
    double convertedNumber = [[ending stringByReplacingOccurrencesOfString:@"," withString:@"."] doubleValue];

//Devices listed here: https://stackoverflow.com/questions/19584208/identify-new-iphone-model-on-xcode-5-5c-5s

    if ([platform containsString:@"iPhone"]) {
        if (convertedNumber >= 7.1) { // 6 and above
            return YES;
        }else{
            return NO; //less than a 6 (ie 5S and below)
        }
    }else if ([platform containsString:@"iPad"]){
        if (convertedNumber >= 5.3) { //iPad Air 2 and above
            return YES;
        }else{
            return NO; //iPad Mini 3 and below
        }
    }

    //Failsafe
    return NO;
}

The link that's commented in the code: Identify new iPhone model on xcode (5, 5c, 5s)

Note. Due to having containsString, this will crash on iOS versions less than 8. To support <8.0, try using the following code to retro-fit this function https://stackoverflow.com/a/26416172/1197723

Have fun!



来源:https://stackoverflow.com/questions/28532649/how-do-i-restrict-my-app-for-only-iphone-6-and-6-plus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!