NSURLCredentialStorage Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in OS X v10.2 and later.
Companion guide
Declared in
NSURLCredentialStorage.h

Overview

NSURLCredentialStorage implements a singleton (shared object) that manages the credential storage.

Tasks

Getting the Credential Storage

Getting and Setting Default Credentials

Adding and Removing Credentials

Retrieving Credentials

Class Methods

sharedCredentialStorage

Returns the shared URL credential storage object.

+ (NSURLCredentialStorage *)sharedCredentialStorage
Return Value

The shared NSURLCredentialStorage object.

Availability
  • Available in OS X v10.2 and later.
Declared In
NSURLCredentialStorage.h

Instance Methods

allCredentials

Returns a dictionary containing the credentials for all available protection spaces.

- (NSDictionary *)allCredentials
Return Value

A dictionary containing the credentials for all available protection spaces. The dictionary has keys corresponding to the NSURLProtectionSpace objects. The values for the NSURLProtectionSpace keys consist of dictionaries where the keys are user name strings, and the value is the corresponding NSURLCredential object.

Availability
  • Available in OS X v10.2 and later.
Declared In
NSURLCredentialStorage.h

credentialsForProtectionSpace:

Returns a dictionary containing the credentials for the specified protection space.

- (NSDictionary *)credentialsForProtectionSpace:(NSURLProtectionSpace *)protectionSpace
Parameters
protectionSpace

The protection space whose credentials you want to retrieve.

Return Value

A dictionary containing the credentials for protectionSpace. The dictionary’s keys are user name strings, and the value is the corresponding NSURLCredential.

Availability
  • Available in OS X v10.2 and later.
Declared In
NSURLCredentialStorage.h

defaultCredentialForProtectionSpace:

Returns the default credential for the specified protectionSpace.

- (NSURLCredential *)defaultCredentialForProtectionSpace:(NSURLProtectionSpace *)protectionSpace
Parameters
protectionSpace

The URL protection space of interest.

Return Value

The default credential for protectionSpace or nil if no default has been set.

Availability
  • Available in OS X v10.2 and later.
Declared In
NSURLCredentialStorage.h

removeCredential:forProtectionSpace:

Removes a specified credential from the credential storage for the specified protection space.

- (void)removeCredential:(NSURLCredential *)credential forProtectionSpace:(NSURLProtectionSpace *)protectionSpace
Parameters
credential

The credential to remove.

protectionSpace

The protection space from which to remove the credential.

Availability
  • Available in OS X v10.2 and later.
Declared In
NSURLCredentialStorage.h

removeCredential:forProtectionSpace:options:

Removes a specified credential from the credential storage for the specified protection space using the given options.

- (void)removeCredential:(NSURLCredential *)credential forProtectionSpace:(NSURLProtectionSpace *)space options:(NSDictionary *)options
Parameters
credential

The credential to remove.

protectionSpace

The protection space from which to remove the credential.

options

A dictionary containing options to consider when removing the credential.

For possible keys, see “Dictionary Key for Credential Removal Options.” You should use this when trying to delete a credential that has the NSURLCredentialPersistenceSynchronizable policy.

Note: When NSURLCredential objects that have a NSURLCredentialPersistenceSynchronizable policy are removed, the credential will be removed on all devices that contain this credential.

Discussion

The credential is removed from both persistent and temporary storage.

Availability
  • Available in OS X v10.9 and later.
Declared In
NSURLCredentialStorage.h

setCredential:forProtectionSpace:

Adds credential to the credential storage for the specified protectionSpace.

- (void)setCredential:(NSURLCredential *)credential forProtectionSpace:(NSURLProtectionSpace *)protectionSpace
Parameters
credential

The credential to add. If a credential with the same user name already exists in protectionSpace, then credential replaces the existing object.

protectionSpace

The protection space to which to add the credential.

Discussion

If the credential is not yet in the set for the protection space, it will be added to it.

Availability
  • Available in OS X v10.2 and later.
Declared In
NSURLCredentialStorage.h

setDefaultCredential:forProtectionSpace:

Sets the default credential for a specified protection space.

- (void)setDefaultCredential:(NSURLCredential *)credential forProtectionSpace:(NSURLProtectionSpace *)protectionSpace
Parameters
credential

The URL credential to set as the default for protectionSpace. If the receiver does not contain credential in the specified protectionSpace it will be added.

protectionSpace

The protection space whose default credential is being set.

Availability
  • Available in OS X v10.2 and later.
Declared In
NSURLCredentialStorage.h

Constants

Dictionary Key for Credential Removal Options

Key used by the options dictionary passed in removeCredential:forProtectionSpace:options:.

NSString *const NSURLCredentialStorageRemoveSynchronizableCredentials;
Constants
NSURLCredentialStorageRemoveSynchronizableCredentials

The corresponding value is an NSNumber object representing a Boolean value that indicates whether credentials which contain the NSURLCredentialPersistenceSynchronizable attribute should be removed.

If the key is missing or the value is @NO, then no attempt will be made to remove such a credential.

Available in OS X v10.9 and later.

Declared in NSURLCredentialStorage.h.

Notifications

NSURLCredentialStorageChangedNotification

This notification is posted when the set of stored credentials changes.

The notification object is the NSURLCredentialStorage instance. This notification does not contain a userInfo dictionary.

Availability
Declared In
NSURLCredentialStorage.h