Sunday, June 16, 2013

NSHTTPCookieStorage NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain example in Objective C (iOS).


NSHTTPCookieStorage NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain

NSHTTPCookieAcceptPolicy
NSHTTPCookieAcceptPolicy specifies the cookie acceptance policies implemented by the NSHTTPCookieStorage class.

typedef enum {
NSHTTPCookieAcceptPolicyAlways,
NSHTTPCookieAcceptPolicyNever,
NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain
} NSHTTPCookieAcceptPolicy;

Constants
NSHTTPCookieAcceptPolicyAlways
Accept all cookies. This is the default cookie accept policy.
NSHTTPCookieAcceptPolicyNever
Reject all cookies.
NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain
Accept cookies only from the main document domain.

NSHTTPCookieStorage NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain example.
- (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];
}
}

End of NSHTTPCookieStorage NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain example article.