Colin Whitmarsh
Colin Whitmarsh

Reputation: 356

How to listen for cookie being set in iOS NSHTTPCookieStorage?

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.

Upvotes: 3

Views: 1342

Answers (1)

Dipesh Pokhrel
Dipesh Pokhrel

Reputation: 432

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];

Upvotes: 3

Related Questions