투케이2K

147. (Objective-C/objc) NSProcessInfo 사용해 시뮬레이터 앱 구동 여부 확인 - SIMULATOR_DEVICE_NAME 본문

Objective-C

147. (Objective-C/objc) NSProcessInfo 사용해 시뮬레이터 앱 구동 여부 확인 - SIMULATOR_DEVICE_NAME

투케이2K 2024. 5. 17. 13:14
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : OBJECTIVE-C

 

[소스 코드]

// ------------------------------------------------------------------------------
// MARK: - [헤더 파일에 정의 없이 : void 메소드 구현]
// ------------------------------------------------------------------------------
- (void)testMain {
    [S_Log _D_WithC_:[NSString stringWithFormat:@"%s", __FILE__]
            M_:[NSString stringWithFormat:@"%s :: %d", __FUNCTION__, __LINE__]
            description:@"테스트 함수 시작 실시" data:nil];

    
    
    // [try catch 구문 정의 실시]
    @try {
        
        // ---------------------------------------------
        // [로직 처리 실시]
        // ---------------------------------------------
        //*
        dispatch_async(dispatch_get_main_queue(), ^{
            
            // [시뮬레이터 판단 실시]
            NSString *modelName = NSProcessInfo.processInfo.environment[@"SIMULATOR_DEVICE_NAME"];
            if (modelName.length > 0) {
                
                [S_Log _F_WithC_:[NSString stringWithFormat:@"%s", __FILE__]
                        M_:[NSString stringWithFormat:@"%s :: %d", __FUNCTION__, __LINE__]
                        description:@"앱 :: 시뮬레이터 동작"
                        data:NULL];
                return;
            }
            
            // [로그 출력]
            [S_Log _F_WithC_:[NSString stringWithFormat:@"%s", __FILE__]
                    M_:[NSString stringWithFormat:@"%s :: %d", __FUNCTION__, __LINE__]
                    description:@"앱 :: 실제 기기 동작"
                    data:NULL];
            
        });
        // */
        // ---------------------------------------------

    }
    @catch (NSException *exception) {
        NSLog(@"\n[NSException : 예외 상황 발생] : %s\n", exception.description.UTF8String);
    }
}
 

[결과 출력]

 

 

 

반응형
Comments