투케이2K

356. (ios/swift5) FileAttributeKey.creationDate 사용해 앱 최초 설치 시간 확인 - FileManager 본문

IOS

356. (ios/swift5) FileAttributeKey.creationDate 사용해 앱 최초 설치 시간 확인 - FileManager

투케이2K 2023. 10. 27. 13:04
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : SWIFT5

 

[소스 코드]

    // -----------------------------------------------------------------------------------------
    // MARK: - [앱 최초 설치 시점 시간 확인]
    // -----------------------------------------------------------------------------------------
    func appInstallFirstTime() -> String {
        
        /*
        // -----------------------------------------
        [appInstallFirstTime 메소드 설명]
        // -----------------------------------------
        1. 앱 최초 설치 시점 시간 확인
        // -----------------------------------------
        2. 호출 방법 :
         
         C_App().appInstallFirstTime()
        // -----------------------------------------
        3. 리턴 데이터 :
         
         2023-10-27 11:17:25
        // -----------------------------------------
        */
        
        
        // [초기 리턴 데이터 변수 선언 실시]
        var returnData = ""
        
        
        // [로직 처리 실시]
        let fileManager = FileManager.default // 파일 매니저 선언
        let documentsUrl =  fileManager.urls(for: .documentDirectory, in: .userDomainMask).last // 기본 경로 확인
        
        if documentsUrl != nil {
            
            let installDate = (try! FileManager.default.attributesOfItem(atPath:documentsUrl!.path)[FileAttributeKey.creationDate])
            
            // [리턴 변수에 삽입]
            let dateFormatter = DateFormatter() // Date 포맷 객체 선언
            
            dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" // Date 포맷 타입 지정
            returnData = dateFormatter.string(from: installDate as! Date) // 포맷된 형식 문자열로 반환
            
        }
        
        
        // [로그 출력 실시]
        S_Log._D_(description: "앱 최초 설치 시점 시간 확인", data: [
            "RETURN :: \(returnData)"
        ])
        
        
        // [리턴 반환 실시]
        return returnData
    }
 

[결과 출력]

 

================================================================
LOG :: CLASS PLACE :: C_App.swift :: appInstallFirstTime() :: 973
-------------------------------------------------
LOG :: NOW TIME :: 2023-10-27 12:56:41
-------------------------------------------------
LOG :: DESCRIPTION :: 앱 최초 설치 시점 시간 확인
-------------------------------------------------
LOG :: RETURN :: 2023-10-27 11:17:25
================================================================

 

반응형
Comments