본문 바로가기

개발도구/iOS - 아이폰 개발

[iOS] WKWebview - Webview 마이그레이션

Migrating from UIWebView / WebView to WKWebView

WKWebView has been the preferred API since iOS 8. But if your app still hasn’t made the switch, be advised that UIWebView and WebView are formally deprecated in iOS 12 and macOS Mojave, and you should update to WKWebView as soon as possible.

To help make that transition, here’s a comparison of the APIs of UIWebView and WKWebView:

UIWebViewWKWebView

var scrollView: UIScrollView { get } var scrollView: UIScrollView { get }
  var configuration: WKWebViewConfiguration { get }
var delegate: UIWebViewDelegate? var UIDelegate: WKUIDelegate?
  var navigationDelegate: WKNavigationDelegate?
  var backForwardList: WKBackForwardList { get }

Loading

UIWebViewWKWebView

func loadRequest(request: URLRequest) func load(_ request: URLRequest) -> WKNavigation?
func loadHTMLString(string: String, baseURL: URL?) func loadHTMLString(_: String, baseURL: URL?) -> WKNavigation?
func loadData(_ data: Data, mimeType: String, characterEncodingName: String, baseURL: URL) -> WKNavigation?  
  var estimatedProgress: Double { get }
  var hasOnlySecureContent: Bool { get }
func reload() func reload() -> WKNavigation?
  func reloadFromOrigin(Any?) -> WKNavigation?
func stopLoading() func stopLoading()
var request: URLRequest? { get }  
  var URL: URL? { get }
  var title: String? { get }

History

UIWebViewWKWebView

  func goToBackForwardListItem(item: WKBackForwardListItem) -> WKNavigation?
func goBack() func goBack() -> WKNavigation?
func goForward() func goForward() -> WKNavigation?
var canGoBack: Bool { get } var canGoBack: Bool { get }
var canGoForward: Bool { get } var canGoForward: Bool { get }
var loading: Bool { get } var loading: Bool { get }

Javascript Evaluation

UIWebViewWKWebView

func stringByEvaluatingJavaScriptFromString(script: String) -> String  
  func evaluateJavaScript(_ javaScriptString: String, completionHandler: ((AnyObject?, NSError?) -> Void)?)

Miscellaneous

UIWebViewWKWebView

var keyboardDisplayRequiresUserAction: Bool  
var scalesPageToFit: Bool  
  var allowsBackForwardNavigationGestures: Bool

Pagination

WKWebView currently lacks equivalent APIs for paginating content.

  • var paginationMode: UIWebPaginationMode
  • var paginationBreakingMode: UIWebPaginationBreakingMode
  • var pageLength: CGFloat
  • var gapBetweenPages: CGFloat
  • var pageCount: Int { get }

출처 : https://nshipster.com/wkwebview/