투케이2K

150. (ios/swift) 웹뷰 (webview) 에서 html 파일 경로 설정 및 로드 방법 본문

IOS

150. (ios/swift) 웹뷰 (webview) 에서 html 파일 경로 설정 및 로드 방법

투케이2K 2022. 5. 10. 09:13
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : SWIFT

 

[방법 설명]

 

[소스 코드]

 

        // -----------------------------------------
        // [wkwebview 웹뷰 html 파일 로드]
        ///*
        guard let localFilePath = Bundle.main.path(forResource: "TwokManagerWeb/html/startHtmlProject", ofType: "html")
        else {
            print("")
            print("====================================")
            print("[\(self.ACTIVITY_NAME) >> init_WebView() :: 웹뷰 로드 수행]")
            print("-------------------------------")
            print("error :: file path is nil")
            print("====================================")
            print("")
            return
        }
        let urlFile = URL(fileURLWithPath: localFilePath) // [url 형식 변환]
        let request = URLRequest(url: urlFile) // [url request 지정]
        self.main_webview!.load(request as URLRequest) // [웹뷰 로드 수행 실시]
        // */
        // -----------------------------------------

 

반응형
Comments