Instance Method


Adds an array of cookies to the cookie storage if the storage’s cookie acceptance policy permits.


- (void)setCookies:(NSArray<NSHTTPCookie *> *)cookies forURL:(NSURL *)URL mainDocumentURL:(NSURL *)mainDocumentURL;



The cookies to add.


The URL associated with the added cookies.


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 NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain.


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 NSHTTPCookieAcceptPolicyNever, the cookies are ignored.

To store cookies from a set of response headers, an application can use cookiesWithResponseHeaderFields:forURL: 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:forTask:.

See Also

Adding and Removing Cookies

- removeCookiesSinceDate:

Removes cookies that were stored after a given date.

- deleteCookie:

Deletes the specified cookie from the cookie storage.

- setCookie:

Stores a specified cookie in the cookie storage if the cookie accept policy permits.

- storeCookies:forTask:

Stores an array of cookies in the cookie storage, on behalf of the provided task, if the cookie accept policy permits.