1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WKWebViewのAppleドキュメント参照メモ

Posted at

WKWEbView

アプリ内ブラウザなどのインタラクティブWebコンテンツを表示するオブジェクト。

重要

iOS 8.0およびOS X 10.10以降では、WKWebViewを使用してねとのこと

note

You can make POST requests with httpBody content in a WKWebView.
↓
あなたはWKWebViewのhttpBodyコンテンツでPOSTリクエストをすることができます。

これちょっとどういうことだろう? よくわからん

httpBody

The data sent as the message body of a request, such as for an HTTP POST request.
HTTP POST要求など、要求のメッセージ本文として送信されたデータのことらしい

使い方

プロパティとして存在しているのね。
これを使ってPOSTリクエストをしろってことか

var httpBody: Data? { get set }

概要

After creating a new WKWebView object using the init(frame:configuration:) method,
 you need to load the web content. 
↓
init(frame:configuration :)メソッドを使用して新しいWKWebViewオブジェクトを作成した後は、
Webコンテンツを読み込む必要があります。
 Use the loadHTMLString(_:baseURL:) method to begin loading local HTML files or the load(_:) method to begin loading web content. 
↓
ローカルHTMLファイルの読み込みを開始するにはloadHTMLString(_:baseURL :)メソッドを使用するか、Webコンテンツの読み込みを開始するにはload(_ :)メソッドを使用します。
Use the stopLoading() method to stop loading, and the isLoading property to find out if a web view is in the process of loading. 
↓
読み込みを停止するにはstopLoading()メソッドを使用し、Webビューが読み込み中かどうかを調べるにはisLoadingプロパティを使用します

なるほど

Set the delegate property to an object conforming to the WKUIDelegate protocol to track the loading of web content.
↓
Webコンテンツのロードを追跡するには、WKUIDelegateプロトコルに準拠したオブジェクトにデリゲートプロパティを設定します。
 See Listing 1 for an example of creating a WKWebView programmatically.
↓
プログラムでWKWebViewを作成する例については、リスト1を参照してください。

ちゃんと例示をしてくれている。優しい

import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
    
    var webView: WKWebView!
    
    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let myURL = URL(string:"https://www.apple.com")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
    }}
To allow the user to move back and forward through the webpage history, use the goBack() and goForward() methods as actions for buttons. Use the canGoBack and canGoForward properties to disable the buttons when the user can’t move in a direction.
↓
ユーザーがWebページの履歴を前後に移動できるようにするには、ボタンのアクションとしてgoBack()メソッドとgoForward()メソッドを使用します。
 canGoBackおよびcanGoForwardプロパティを使用して、ユーザーがある方向に移動できないときにボタンを無効にします。

By default, a web view automatically converts telephone numbers that appear in web content to Phone links. When a Phone link is tapped, the Phone app launches and dials the number. To turn off this default behavior, set the dataDetectorTypes property with a WKDataDetectorTypes bitfield that does not contain the phoneNumber flag.
↓
デフォルトでは、WebビューはWebコンテンツに表示される電話番号を自動的に電話リンクに変換します。
電話リンクがタップされると、電話アプリが起動して番号をダイヤルします。

このデフォルトの動作を無効にするには
phoneNumberフラグを含まないWKDataDetectorTypesビットフィールドでdataDetectorTypesプロパティを設定します。

You can also use the setMagnification(_:centeredAt:) to programmatically set the scale of web content the first time it is displayed in a web view. Thereafter, the user can change the scale using gestures.
↓
setMagnification(_:centeredAt :)を使用して、Webビューに最初に表示されるときにWebコンテンツのスケールをプログラムで設定することもできます。その後、ユーザーはジェスチャーを使用してスケールを変更できます。
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?