How to listen for cookie being set in iOS NSHTTPCookieStorage?

1.1k Views Asked by At

I'd like to know when a cookie is set in NSHTTPCookieStorage. Is there an on change method or event handler? I'd like to prevent a cookie from being set.

1

There are 1 best solutions below

0
On BEST ANSWER

You can listen to the cookie changes by the following notification.

NSHTTPCookieManagerCookiesChangedNotification.

Apple documentation link below.

https://developer.apple.com/documentation/foundation/nshttpcookiemanagercookieschangednotification?language=objc

Example:

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(methodYouWantToInvoke) //note the ":" - should take an NSNotification as parameter
                                                 name:NSHTTPCookieManagerCookiesChangedNotification
                                               object:nil];