#if check (preprocessor macro) to differentiate between iPhone and iPad

后端 未结 5 1134
别那么骄傲
别那么骄傲 2021-02-04 12:13

Is there a build preprocessor macro I can check, with #if or #ifdef to determine if my current Xcode project is being built for iPhone or iPad?

5条回答
  •  梦谈多话
    2021-02-04 13:15

    I use the following code for AppleTV 4 because UIUserInterfaceIdiomUnspecified, doesn't seem to work, nor can I find any other enums:

    #ifdef TARGET_OS_IOS
    CGSize result = [[UIScreen mainScreen] bounds].size;
        if(result.width == 1920) {
            NSLog(@"tvOS");
        }
    #endif
    

    I used to use this for iPad and such before the dark times, before the empire- OB1, hah good night. But you can use this similar technique for other screen sizes you know of.

提交回复
热议问题