yoogail105 / KkokkoSwift

꼬리에 꼬리를 무는 swift 개념 정리
28 stars 0 forks source link

11. 웹 뷰: 앱에서 웹 페이지를 여는 방법 #78

Open yoogail105 opened 2 years ago

yoogail105 commented 2 years ago

11. 웹 뷰: 앱에서 웹 페이지를 여는 방법

yoogail105 commented 2 years ago

1. 사파리 앱 호출

  1. 장점 사파리 앱을 그대로 호출, ATS 설정 필요 X(App Transport Security, 네트워크 통신을 사파리 앱이 대신 처리, info.plist에 HTTP보안 허가 X)
    → 구현 쉬움

  2. 단점 기존 뷰에서 여는 것이 아니라 새로운 사파리 앱을 호출→ 포커스 벗어남 → 추천 X

let url = URL(string: "https://www.apple.com/")
UIApplication.shared.open(url!, options:[:])
yoogail105 commented 2 years ago

2. UIWebView

3. WKWebView

import Webkit

@IBOutlet var webView: WKWebView!

guard let url = URL(string: "https://www.apple.com/") else { return }
let req = URLRequest(url: url!)

self.webView.load(req)

WKWebView 메소드

웹뷰와 델리게이트 패턴

yoogail105 commented 2 years ago

4. SFSafariViewController

import SafariServices

 @IBAction func btnAction(_ sender: Any) {
        let url = URL(string: "https://www.apple.com/")
        let safariViewController = SFSafariViewController(url: url!)
        present(safariViewController, animated: true)
    }
yoogail105 commented 2 years ago

🍫참고