NSURLCredential Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in iOS 2.0 and later. |
| Companion guide | |
| Declared in | NSURLCredential.h |
Overview
NSURLCredential is an immutable object representing an authentication credential consisting of authentication information specific to the type of credential and the type of persistent storage to use, if any.
Adopted Protocols
Tasks
Creating a Credential
-
+ credentialForTrust: -
+ credentialWithUser:password:persistence: -
+ credentialWithIdentity:certificates:persistence: -
– initWithIdentity:certificates:persistence: -
– initWithTrust: -
– initWithUser:password:persistence:
Getting Credential Properties
Class Methods
credentialForTrust:
Creates and returns an NSURLCredential object for server trust authentication with a given accepted trust.
Parameters
- trust
The accepted trust.
Discussion
Before creating a server trust credential, it is the responsibility of the delegate of an NSURLConnection object or an NSURLDownload object to evaluate the trust. Do this by calling SecTrustEvaluate, passing it the trust obtained from the serverTrust method of the server’s NSURLProtectionSpace object. If the trust is invalid, the authentication challenge should be cancelled with cancelAuthenticationChallenge:.
Availability
- Available in iOS 3.0 and later.
Declared In
NSURLCredential.hcredentialWithIdentity:certificates:persistence:
Creates and returns an NSURLCredential object for client certificate authentication with a given identity and a given array of client certificates using a given persistence setting.
Parameters
- identity
The identity for the credential.
- certArray
An array of one or more
SecCertificateRefobjects representing certificates for the credential.- persistence
The persistence setting for the credential.
Availability
- Available in iOS 3.0 and later.
Declared In
NSURLCredential.hcredentialWithUser:password:persistence:
Creates and returns an NSURLCredential object for internet password authentication with a given user name and password using a given persistence setting.
Parameters
- user
The user for the credential.
- password
The password for user.
- persistence
The persistence setting for the credential.
Return Value
An NSURLCredential object with user name user, password password, and using persistence setting persistence.
Discussion
If persistence is NSURLCredentialPersistencePermanent the credential is stored in the keychain.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCredential.hInstance Methods
certificates
Returns an array of SecCertificateRef objects representing the certificates of the credential if it is a client certificate credential.
Return Value
The certificates of the credential, or nil if this is not a client certificate credential.
Availability
- Available in iOS 3.0 and later.
Declared In
NSURLCredential.hhasPassword
Returns a Boolean value that indicates whether the receiver has a password.
Return Value
YES if the receiver has a password, NO otherwise.
Discussion
This method does not attempt to retrieve the password.
If this credential's password is stored in the user’s keychain, password may return NO even if this method returns YES, since getting the password may fail, or the user may refuse access.
Availability
- Available in iOS 2.0 and later.
Declared In
NSURLCredential.hidentity
Returns the identity of this credential if it is a client certificate credential.
Return Value
The identity of the credential, or NULL if this is not a client certificate credential.
Availability
- Available in iOS 3.0 and later.
Declared In
NSURLCredential.hinitWithIdentity:certificates:persistence:
Returns an NSURLCredential object for client certificate authentication initialized with a given identity and a given array of client certificates using a given persistence setting.
Parameters
- identity
The identity for the credential.
- certArray
An array of one or more
SecCertificateRefobjects representing certificates for the credential.- persistence
The persistence setting for the credential.
Availability
- Available in iOS 3.0 and later.
Declared In
NSURLCredential.hinitWithTrust:
Returns an NSURLCredential object for server trust authentication initialized with a given accepted trust.
Parameters
- trust
The accepted trust.
Discussion
Before creating a server trust credential, it is the responsibility of the delegate of an NSURLConnection object or an NSURLDownload object to evaluate the trust. Do this by calling SecTrustEvaluate, passing it the trust obtained from the serverTrust method of the server’s NSURLProtectionSpace object. If the trust is invalid, the authentication challenge should be cancelled with cancelAuthenticationChallenge:.
Availability
- Available in iOS 3.0 and later.
Declared In
NSURLCredential.hinitWithUser:password:persistence:
Returns an NSURLCredential object initialized with a given user name and password using a given persistence setting.
Parameters
- user
The user for the credential.
- password
The password for user.
- persistence
The persistence setting for the credential.
Return Value
An NSURLCredential object initialized with user name user, password password, and using persistence setting persistence.
Discussion
If persistence is NSURLCredentialPersistencePermanent the credential is stored in the keychain.
Availability
- Available in iOS 2.0 and later.
Declared In
NSURLCredential.hpassword
Returns the receiver’s password.
Return Value
The receiver’s password.
Discussion
If the password is stored in the user’s keychain, this method may result in prompting the user for access.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCredential.hpersistence
Returns the receiver’s persistence setting.
Return Value
The receiver’s persistence setting.
Availability
- Available in iOS 2.0 and later.
Declared In
NSURLCredential.huser
Returns the receiver’s user name.
Return Value
The receiver’s user name.
Availability
- Available in iOS 2.0 and later.
Declared In
NSURLCredential.hConstants
NSURLCredentialPersistence
These constants specify how long the credential will be kept.
typedef enum {
NSURLCredentialPersistenceNone,
NSURLCredentialPersistenceForSession,
NSURLCredentialPersistencePermanent
} NSURLCredentialPersistence;
Constants
NSURLCredentialPersistenceNoneCredential won't be stored.
Available in iOS 2.0 and later.
Declared in
NSURLCredential.h.NSURLCredentialPersistenceForSessionCredential will be stored only for this session.
Available in iOS 2.0 and later.
Declared in
NSURLCredential.h.NSURLCredentialPersistencePermanentCredential will be stored in the user’s keychain and shared with other applications.
Available in iOS 2.0 and later.
Declared in
NSURLCredential.h.
Availability
- Available in iOS 2.0 and later.
Declared In
NSURLCredential.h© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-08-12)