setCookies(_:for:mainDocumentURL:)
Adds an array of cookies to the cookie storage if the storage’s cookie acceptance policy permits.
Declaration
func setCookies(_ cookies: [HTTPCookie], for URL: URL?, mainDocumentURL: URL?)Parameters
- cookies:
The cookies to add.
- URL:
The URL associated with the added cookies.
- mainDocumentURL:
The URL of the main HTML document for the top-level frame, if known. The value can be
nil. This URL is used to determine whether the cookie should be accepted if the cookie accept policy is Onlyfrommaindocumentdomain.
Discussion
Cookies in the array will replace existing cookies with the same name, domain, and path in the cookie storage. If the storage has an accept policy of HTTPCookie.AcceptPolicy.never, the cookies are ignored.
To store cookies from a set of response headers, an application can use cookies(withResponseHeaderFields:for:) passing a header field dictionary and then use this method to store the resulting cookies in accordance with the cookie storage’s cookie acceptance policy.
If you override this method, also override storeCookies(_:for:).