Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BollywooD

macrumors 6502
Original poster
Apr 27, 2005
372
46
Hamburg
I am building/updating a cookie manager, and would like to bind Safari's cookie policy (Never/Always/Only from sites I visit) and an extra(only from whitelisted sites) to my own implementation with the same values.

Is this possible?

I have found NSHTTPCookieAcceptPolicy, and thought that would be a good place to start, but are a little lost.

does anyone have any ideas, how to acheive what I want.


thanks in advance.
 

BollywooD

macrumors 6502
Original poster
Apr 27, 2005
372
46
Hamburg
I have added a notification, using notification centre to: NSHTTPCookieManagerAcceptPolicyChangedNotification
using the following code:
Code:
NSNotificationCenter * ncpolicy = [NSNotificationCenter defaultCenter];
	[ncpolicy addObserver:self selector:@selector(_cookiePolicyChangedNotification:) 
					 name:NSHTTPCookieManagerAcceptPolicyChangedNotification object:nil];

but when I change the policy in Safari, I dont receive any notifications?

Has this changed in Safari 4?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
It might be a distributed notification. Try using NSDistributedNotificationCenter instead.
 

BollywooD

macrumors 6502
Original poster
Apr 27, 2005
372
46
Hamburg
OK,

so ive got syncing happening oneway..... when I change the behaviour in Safari, this is reflected in my App.

but not the other way?

I am using the following function:

Code:
- (IBAction) changeCookiePolicyButton:(id)sender
{	
	[[SCPreferences userDefaults] synchronize];
	int policyKey;
	policyKey = [[SCPreferences userDefaults]  integerForKey:SCPreferencesCookieAcceptPolicy];
	if (policyKey == 0)
	{
		[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
	}
	if (policyKey == 1)
	{
		[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyNever];
	}
	if (policyKey == 2)
	{
		[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain];
	}
}

any ideas?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
I would be surprised if Safari actually changes its preferences when other apps change that value.

Edit: well according to the docs it looks like it should. Maybe Safari is special...
 

BollywooD

macrumors 6502
Original poster
Apr 27, 2005
372
46
Hamburg
Duh....

I have 2 IBActions, with similar sounding names.....

IB cuts the ends of the names of in the inspector panel, so I had my connections wrong!

The code posted above, does in fact work.
:eek:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.