Objective-C

177. (Objective-C/objc) [간단 소스] NFCNDEFReaderSession.readingAvailable 사용해 NFC 기능 사용 가능 상태 확인 수행

투케이2K 2025. 1. 19. 10:58

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : OBJECTIVE-C

 

[소스 코드]

 

// --------------------------------------------------------------------------------------
[개발 및 테스트 환경]
// --------------------------------------------------------------------------------------

- 언어 : Objective-c

- 개발 툴 : Xcode

- 기술 구분 : NFC / Support

// --------------------------------------------------------------------------------------






// --------------------------------------------------------------------------------------
[소스 코드]
// --------------------------------------------------------------------------------------

- (void)testMain {
    [S_Log _D_WithC_:[NSString stringWithFormat:@"%s", __FILE__]
            M_:[NSString stringWithFormat:@"%s :: %d", __FUNCTION__, __LINE__]
            description:@"테스트 함수 시작 실시" data:nil];

    /*
    // -----------------------------------------
    [요약 설명]
    // -----------------------------------------
    1. 필요 import 및 info.plist 권한 설정 :
      
      import CoreNFC
      
      Privacy - NFC Scan Usage Description
    // -----------------------------------------
    2. Xcode 에서 NFC 기능 사용 설정 방법 :
      
      https://blog.naver.com/kkh0977/223729651712
    // -----------------------------------------
    */

    
    
    // [try catch 구문 정의 실시]
    @try {
        
        // ---------------------------------------------
        // [로직 처리 실시]
        // ---------------------------------------------
        //*
        dispatch_async(dispatch_get_main_queue(), ^{
            
            if (@available(iOS 11.0, *)) {
                if (NFCNDEFReaderSession.readingAvailable) {
                    NSLog(@"NFC NDEF reading is available on this device.");
                } else {
                    NSLog(@"NFC NDEF reading is not available on this device.");
                }
            } else {
                NSLog(@"NFC is not supported on this iOS version.");
            }
            
        });
        // */
        // ---------------------------------------------

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

// --------------------------------------------------------------------------------------

반응형