투케이2K

372. (ios/swift5) [App Scheme] shareddocuments: 스키마 사용해 앱 특정 폴더 이동 수행 실시 - FileManager document 본문

IOS

372. (ios/swift5) [App Scheme] shareddocuments: 스키마 사용해 앱 특정 폴더 이동 수행 실시 - FileManager document

투케이2K 2023. 11. 11. 15:42
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : SWIFT5

 

[소스 코드]

    // -----------------------------------------------------------------------------------------
    // MARK: - [앱 특정 디렉토리 이동 수행]
    // -----------------------------------------------------------------------------------------
    func goAppFileDirectory(_path : String) {
        
        /*
        // -----------------------------------------
        [goAppFileDirectory 메소드 설명]
        // -----------------------------------------
        1. 앱 특정 디렉토리 이동 수행
         
         shareddocuments:/Users/mac/Library/Developer/CoreSimulator/Devices/13F32C28-9DCB-445D-8086-5897A1D4FE9E/data/Containers/Data/Application/078329F1-9271-467F-817A-03A1E3AB2E1B/Documents/
        // -----------------------------------------
        2. 호출 예시 :
         
         var path = "shareddocuments:\(FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!)" // 앱 디렉토리 경로 확인
         path = path.replaceAll(_string: "file://", _replace: "")
         
         self.goAppFileDirectory(_path: path)
        // -----------------------------------------
        3. 참고 :
         
         [파일] 앱 특정 디렉토리 폴더에 접근 하기 위해서는 info.plist 권한 등록 필요
         
         아이폰 파일 접근 설정 : Supports opening documents in place : YES
         아이튠즈 공유 설정 : Application supports iTunes file sharing : YES
        // -----------------------------------------
        */
        
        // [메인 큐에서 비동기 방식 실행 : UI 동작 실시]
        DispatchQueue.main.async {
            
            // [사전 인풋 값 널 데이터 체크 수행 실시]
            if _path != nil && _path.count>0 && _path != "" && _path.hasPrefix("shareddocuments:") {
            }
            else {
                S_Log._D_(description: "앱 특정 디렉토리 이동 실패", data: [
                    "error :: 사전 인풋 데이터 체크 에러",
                    "_path :: \(_path)"
                ])

                // [리턴 종료]
                return
            }
            
            
            // [로그 출력 실시]
            S_Log._D_(description: "앱 특정 디렉토리 이동 수행", data: [
                "_path :: \(_path)"
            ])
            
            
            // [외부 링크 이동 수행 실시]
            UIApplication.shared.open(URL(string: _path)!, options: [:])
        }
    }
 

[결과 출력]

 

반응형
Comments