TAG

UIWebView

  • 2020-02-18
  • 2020-02-27

(Swift|ObjC) How to replace UIWebView with WKWebView

On December 23 2019, the following article was post to the Developer News And Updates: Updating Apps that Use Web Views According to that, the App Store will no longer accept the app using UIWebView. I also post the following article: From now, WKWebView and SFSafariViewController are recommended. This article describes how to replace UIWebView with WKWebView. Load the web page From URL The code to load the web page from the specified URL with UIWebView is following: // Swift // With UIWebView func load(url: URL) { let request = URLRequest(url: url) uiWebView.loadRequest(request) } // Objective-C // With UIWebView - (void)loadWithURL:(NSURL *)url { NSURLRequest *request = [NSURLRequest requestWithURL:url]; [self.uiWebView loadRequest:request]; } With WKWebView, the code is following. It is very similar. // Swift // With WKWebView func load(url: URL) { let request = URLRequest(url: url) wkWebView.load(request) } // Objective-C // With WKWebView #import <WebKit/WebKit.h> - (void)loadWithURL:(NSURL *)url { NSURLRequest *request = [NSURLRequest requestWithURL:url]; [self.wkWebView loadRequest:request]; } From Local HTML The code to load the local HTML which is presented by the string with UIWebView is following: // Swift uiWebView.loadHTMLString(html, baseURL: baseURL) // Objective-C [self.uiWebView loadHTMLString:html baseURL:baseURL]; With WKWebView is following. The difference between them is whether the result value is […]

  • 2020-02-18
  • 2020-02-18

Which class is better? WKWebView or SFSafariViewController?

In general, The WKWebView class is better choice when you replace the UIWebView class. However, in some cases, the SFSafariViewController can be better choice. Better class is decided by the requirements Which class is better? You may want to consider following: An app want to do something when read the web page. An app want to know the URL of the web page. An app want to execute the JavaScript on the page. If your app fit to above, your app should use WKWebView. SFSafariViewController can’t do above. Is the requirements really needed? “My app want to do “Something” when read the page”. Is it really needed? For example, your app want to open the specified URL, or want to execute JavaScript to only close the view? It may be enough that by placing the close button on the navigation bar. In some cases, An app display the login page, and received the specified URL, an app close the view. In this case, especially with the OAuth2, you can set the redirect URL to the custom URL Scheme (Deep Link), UIApplicationDelegate can respond to it. You can use SFSafariViewController in this case. Is opening the browser really good UX? Your […]

  • 2020-02-18
  • 2020-02-28

UIWebView will be no longer accepted

To use the embedded web browser in an iOS App, you have three choices: UIWebView Class WKWebView class SFSafariViewController class The long time past since the UIWebView class have been deprecated, now, The AppStore will be no longer accept apps that are using the UIWebView class. Updating Apps that Use Web Views According to above post, the AppStore will be no longer accept new apps are using UIWebView class as of April 2020, app updates using UIWebView class as of December 2020. The way to replace UIWebView to WKWebView, review following article. What to do? Basically you need replace UIWebView with WKWebView, but in some case, you can use SFSafariViewController. For example, if your app simply show the support web site or the login page which is using OAuth2, you can use SFSafariViewController. SFSafariViewController has a feature of Safari. When you display login page are using OAuth2, you set the redirect URL to app deep link URL. The SFSafariViewController can be hidden, your app may hides SFSafariViewController and shows the progress indicator. If you are not sure which class is better, see the next article:

>現役のプログラマーが書くプログラミング情報

現役のプログラマーが書くプログラミング情報

日々の開発の中での学びや分かったこと、調べたことなどを書いていくブログです。

CTR IMG