투케이2K

139. (Objective-C/objc) CTTelephonyNetworkInfo CellularProviders 사용해 휴대폰 유심 Usim 장착 상태 확인 본문

Objective-C

139. (Objective-C/objc) CTTelephonyNetworkInfo CellularProviders 사용해 휴대폰 유심 Usim 장착 상태 확인

투케이2K 2023. 11. 12. 17:52
반응형

[개발 환경 설정]

개발 툴 : 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];

    /*
     ------------------------------------
     [요약 설명]
     ------------------------------------
     1. 필요 import :
     
     #import <CoreTelephony/CTTelephonyNetworkInfo.h>
     #import <CoreTelephony/CTCarrier.h>
     ------------------------------------
     2. CTTelephonyNetworkInfo providers를 조회하여 mobileNetworkCode가 있는 경우를 USIM이 있는 경우로 판단
     ------------------------------------
     */

    
    
    // [try catch 구문 정의 실시]
    @try {
        
        // ---------------------------------------------
        // [로직 처리 실시]
        // ---------------------------------------------
        //*
        dispatch_async(dispatch_get_main_queue(), ^{
            
            // [CTTelephonyNetworkInfo 선언]
            CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
            NSDictionary<NSString *, CTCarrier *> *providers = [networkInfo serviceSubscriberCellularProviders];

            if (providers != nil) {
                
                NSString *M_LOG = @"[ERROR] :: Usim Search Fail";

                for (NSString *key in [providers allKeys]) {
                    
                    CTCarrier *carrier = [providers valueForKey:key];
                
                    NSString *mnc = carrier.mobileNetworkCode;
                    NSString *mcc = carrier.mobileCountryCode;
                    
                    if (mnc == nil) {
                        //NSLog(@"USIM 없음");
                    } else {
                        //NSLog(@"USIM 있음");
                        M_LOG = @"[Success] :: Usim Mounting Device";
                    }
                }
                
                [S_Log _D_WithC_:[NSString stringWithFormat:@"%s", __FILE__]
                        M_:[NSString stringWithFormat:@"%s :: %d", __FUNCTION__, __LINE__]
                        description:[NSString stringWithFormat:@"유심 장착 상태 확인 :: %@", M_LOG] data:nil];
            }
            else {
                [S_Log _D_WithC_:[NSString stringWithFormat:@"%s", __FILE__]
                        M_:[NSString stringWithFormat:@"%s :: %d", __FUNCTION__, __LINE__]
                        description:@"유심 장착 상태 확인 :: providers is nil" data:nil];
            }
            
        });
        // */
        // ---------------------------------------------
        /*
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ // [10 초 딜레이 실행]
            
        });
        // */
        // ---------------------------------------------

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

[결과 출력]


 
반응형
Comments