WKWebView

1.WKWebView

1.1
WKWebViewConfiguration
1.1.1
WKProcessPool
1.1.2
WKPreferences
1.1.2.1
open var javaScriptCanOpenWindowsAutomatically: Bool
1.1.3
WKUserContentController
1.1.3.1
[WKUserScript]
1.1.3.1.1
open var source: String { get }
1.1.3.1.2
WKUserScriptInjectionTime
1.1.3.1.3
open var isForMainFrameOnly: Bool { get }
1.1.3.2
open func add(_ scriptMessageHandler: WKScriptMessageHandler, name: String)
1.1.3.2.1
WKScriptMessageHandler
1.1.3.3
open func add(_ contentRuleList: WKContentRuleList)
1.1.3.3.1
ios 11
WKContentRuleList
1.1.4
iOS 9.0
WKWebsiteDataStore
1.1.4.1
A WKWebsiteDataRecord object represents website data grouped by the originating URL’s domain name and suffix.
WKWebsiteDataRecord
1.1.4.1.1
open var displayName: String { get }
A WKSecurityOrigin object consists of a host name, a protocol, and a port number. A first-party load is any load URL has the same security origin as the requesting web site. First-party webpages can access each other’s resources such as scripts and databases.
WKSecurityOrigin
1.1.4.2
WKHTTPCookieStore
可以添加cookie 删除cookie 添加通知者等等
1.1.4.2.1
WKHTTPCookieStoreObserver
1.1.4.2.1.1
optional public func cookiesDidChange(in cookieStore: WKHTTPCookieStore)
1.1.4.2.2
HTTPCookie…
1.1.5
/*! @abstract A Boolean value indicating whether the web view suppresses
content rendering until it is fully loaded into memory.
@discussion The default value is NO.
*/
suppressesIncrementalRendering
1.1.6
@available(iOS 9.0, )
The name of the application as used in the user agent string.
open var applicationNameForUserAgent: String? //用了下感觉没啥用 呵呵呵
1.1.7
open var allowsAirPlayForMediaPlayback: Bool
1.1.8
allowsInlineMediaPlayback
1.1.9
/
! @enum WKSelectionGranularity
@abstract The granularity with which a selection can be created and modified interactively.
@constant WKSelectionGranularityDynamic Selection granularity varies automatically based on the selection.
@constant WKSelectionGranularityCharacter Selection endpoints can be placed at any character boundary.
@discussion An example of how granularity may vary when WKSelectionGranularityDynamic is used is
that when the selection is within a single block, the granularity may be single character, and when
the selection is not confined to a single block, the selection granularity may be single block.
*/
WKSelectionGranularity
觉得没啥感觉…
1.1.10
allowsPictureInPictureMediaPlayback
画中画是啥
1.1.11
@available(iOS 10.0, *)
An enum value indicating the type of data detection desired.
@discussion The default value is WKDataDetectorTypeNone.
An example of how this property may affect the content loaded in the WKWebView is that content like
'Visit apple.com on July 4th or call 1 800 555-5545' will be transformed to add links around 'apple.com', 'July 4th' and '1 800 555-5545'
if the dataDetectorTypes property is set to WKDataDetectorTypePhoneNumber | WKDataDetectorTypeLink | WKDataDetectorTypeCalendarEvent.

  • 指定该属性将会给匹配的页面内容增加用户交互@property(nonatomic) WKDataDetectorTypes dataDetectorTypes;
  • 例如,如果将其设为WKDataDetectorTypeLink类型,浏览器将会对页面中的“Visit apple.com” 字符串中的 “apple.com”添加链接
    open var dataDetectorTypes: WKDataDetectorTypes

1.1.12
ignoresViewportScaleLimits
1.1.13
Each URL scheme can only have one handler. An exception is thrown if you register a handler for an invalid URL scheme, if you register a handler for a URL scheme more than once, or if you register a handler for a URL scheme already handled by WebKit. You can call the handlesURLScheme(_:) method to determine whether WebKit handles a particular URLs scheme.URL schemes are case insensitive. Valid URL schemes must start with an ASCII letter and can only contain ASCII letters, numbers, the '+' character, the '-' character, and the '.' character.
open func setURLSchemeHandler(_ urlSchemeHandler: WKURLSchemeHandler?, forURLScheme urlScheme: String)
WKURLSchemeHandler
1.1.13.1
A task created to load a resource.
WKURLSchemeTask
不怎么用到
https://www.jianshu.com/p/67146af7ef50

补充:
javaScriptCanOpenWindowsAutomatically = NO:阻止 JS 自动调动window.open方法打开一个新的webView;
会对JS 的window.open("../index.html");产生影响,JS 调用window.open打开新窗口的时候 WKWebView 会调用WKUIDelegate的代理方法createWebViewWithConfiguration,如果这个代理没实现,设置了javaScriptCanOpenWindowsAutomatically = YES 也没什么用

1.2.0
WKNavigationDelegate
网页加载生命周期的一些代理方法
Decides whether to allow or cancel a navigation.
1.2.0.1
A WKNavigationAction object contains information about an action that may cause a navigation, used for making policy decisions.
WKNavigationAction
@NSCopying open var sourceFrame: WKFrameInfo { get }
@NSCopying open var targetFrame: WKFrameInfo? { get }
open var navigationType: WKNavigationType { get }
open var request: URLRequest { get }
1.2.0.1.1
WKFrameInfo
1.2.0.1.2
The type of action that triggered the navigation
WKNavigationType
1.2.0.2
WKNavigationActionPolicy
WKNavigationActionPolicy
WKNavigationActionPolicyCancel 取消请求
WKNavigationActionPolicyAllow 允许继续
WKNavigationResponsePolicy
WKNavigationResponsePolicyCancel 取消加载
WKNavigationResponsePolicyAllow 允许继续

1.3.0
WKUIDelegate
1.3.0.1
WKNavigationDelegate中的该方法是用户点击网页上的链接,需打开新页面时,将先调,是否允许跳转到链接。
If you do not implement this method, the web view will cancel the navigation.
打个注释不知道啥时候能走到这个方法里
optional public func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView?
https://www.jianshu.com/p/5f4bba47e323
1.3.0.2
都是只读的有毛用
WKWindowFeatures
1.3.1
optional public func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (String?) -> Void)
//! alert按钮
<button onclick = "showAlert()" style = "font-size: 18px;">alert(message)</button>
//! confirm按钮
<button onclick = "showConfirm()" style = "font-size: 18px;">confirm(message)</button>
//! prompt按钮
<button onclick = "showPrompt()" style = "font-size: 18px;">prompt(prompt, defaultText)</button>
1、JS调用alert()方法、confirm()方法和prompt()方法;
2、iOS实现WKUIDelegate协议里面的方法,负责上述JS方法的响应;
https://www.jianshu.com/p/7a1fceae5880
1.3.2
@available(iOS 10.0, *)
optional public func webView(_ webView: WKWebView, shouldPreviewElement elementInfo: WKPreviewElementInfo) -> Bool
等其他方法
1.4.0
open var backForwardList: WKBackForwardList { get }
1.4.0.1
WKBackForwardListItem
1.5
public init(frame: CGRect, configuration: WKWebViewConfiguration)
1.6
If readAccessURL references a single file, only that file may be loaded by WebKit. If readAccessURL references a directory, files inside that file may be loaded by WebKit.
说白了就是加载本地url
URL
The file URL to navigate to.
readAccessURL
The URL to allow read access to.
open func loadFileURL(_ URL: URL, allowingReadAccessTo readAccessURL: URL) -> WKNavigation?
1.7
open func loadHTMLString(_ string: String, baseURL: URL?) -> WKNavigation?
1.8
open var serverTrust: SecTrust? { get }
1.9
customUserAgent 这个我还真设置了 请求没啥反应

有篇文章写的不错 基本都翻译了
https://cloud.tencent.com/developer/article/1033743

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,084评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,623评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,450评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,322评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,370评论 6 390
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,274评论 1 300
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,126评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,980评论 0 275
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,414评论 1 313
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,599评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,773评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,470评论 5 344
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,080评论 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,713评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,852评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,865评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,689评论 2 354

推荐阅读更多精彩内容