Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 9, 2009, 04:57 AM   #1
BollywooD
macrumors 6502
 
Join Date: Apr 2005
NSHTTPCookieAcceptPolicy

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 is offline   0 Reply With Quote
Old Apr 9, 2009, 05:14 PM   #2
BollywooD
Thread Starter
macrumors 6502
 
Join Date: Apr 2005
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?
BollywooD is offline   0 Reply With Quote
Old Apr 9, 2009, 05:57 PM   #3
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
It might be a distributed notification. Try using NSDistributedNotificationCenter instead.
kainjow is offline   0 Reply With Quote
Old Apr 9, 2009, 06:01 PM   #4
BollywooD
Thread Starter
macrumors 6502
 
Join Date: Apr 2005
Quote:
Originally Posted by kainjow View Post
It might be a distributed notification. Try using NSDistributedNotificationCenter instead.
Bingo!

thanks for your help!!
BollywooD is offline   0 Reply With Quote
Old Apr 9, 2009, 09:24 PM   #5
BollywooD
Thread Starter
macrumors 6502
 
Join Date: Apr 2005
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?
BollywooD is offline   0 Reply With Quote
Old Apr 10, 2009, 11:31 AM   #6
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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...

Last edited by kainjow; Apr 10, 2009 at 11:40 AM.
kainjow is offline   0 Reply With Quote
Old Apr 10, 2009, 02:25 PM   #7
BollywooD
Thread Starter
macrumors 6502
 
Join Date: Apr 2005
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.
BollywooD is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

All times are GMT -5. The time now is 09:27 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC