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