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

后端 未结 5 1145
别那么骄傲
别那么骄傲 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 12:53

    NSString *deviceType = [UIDevice currentDevice].model;
    
    if([deviceType isEqualToString:@"iPhone"]) {
        //iPhone
    }
    else if([deviceType isEqualToString:@"iPod touch"]) {
        //iPod Touch
    }
    else {
        //iPad
    }
    

    You cannot, as far as I am concerned, use #if or #ifdef to do this but, it is supported because Obj-C is a strict superset of C.

    Related: Determine device (iPhone, iPod Touch) with iPhone SDK

提交回复
热议问题