[IOS] Objective-C

장치가 iPhone X(노치 시리즈) 감지 방법

최고관리자
2018.12.06 11:03 3,193 0

본문

장치가 iPhone X(노치 시리즈) 감지 방법


Objective-C


if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone) {


        switch ((int)[[UIScreen mainScreen] nativeBounds].size.height) {


            case 1136:

                printf("iPhone 5 or 5S or 5C");

                break;

            case 1334:

                printf("iPhone 6/6S/7/8");

                break;

            case 1920, 2208:

                printf("iPhone 6+/6S+/7+/8+");

                break;

            case 2436:

                printf("iPhone X, Xs");

                break;

               case 2688:

            printf("iPhone Xs Max")

           case 1792:

            printf("iPhone Xr")

            default:

                printf("unknown");

        }

    }



스위프트3 이상


if UIDevice().userInterfaceIdiom == .phone {

        switch UIScreen.main.nativeBounds.height {

        case 1136:

            print("iPhone 5 or 5S or 5C")

        case 1334:

            print("iPhone 6/6S/7/8")

        case 1920, 2208:

            print("iPhone 6+/6S+/7+/8+")

        case 2436:

            print("iPhone X, Xs")

        case 2688:

            print("iPhone Xs Max")

        case 1792:

            print("iPhone Xr")

        default:

            print("unknown")

        }

    }




topNotch로 감지


Objective-C


BOOL iPhoneX = NO;

    if (@available(iOS 11.0, *)) {

        UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];

        if (mainWindow.safeAreaInsets.top > 0.0) {

            iPhoneX = YES;

        }

    }


-(BOOL)hasTopNotch{

if (@available(iOS 11.0, *)) {

    return [[[UIApplication sharedApplication] delegate] window].safeAreaInsets.top > 20.0;

}

return  NO;

}



스위프트

var hasTopNotch: Bool {

if #available(iOS 11.0,  *) {

    return UIApplication.shared.delegate?.window??.safeAreaInsets.top ?? 0 > 20

}

return false

}




다른 방법 1

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {

    CGSize screenSize = [[UIScreen mainScreen] bounds].size;

     // 812.0 on iPhone X, XS.

   // 896.0 on iPhone XS Max, XR.

    if (screenSize.height >= 812.0f)

        NSLog(@"iPhone X");

}

댓글목록 0

등록된 댓글이 없습니다.