NSURLCredentialStorage官方文档阅读

NSURLCredentialStorage

Overview

NSURLCredentialStorage是管理凭据存储的单例(共享对象)。

Symbols

Getting the Credential Storage
  • @property(class, readonly, strong) NSURLCredentialStorage *sharedCredentialStorage

    返回共享的URL证书存储仓库;

Getting and Setting Default Credentials
  • - (NSURLCredential *)defaultCredentialForProtectionSpace:(NSURLProtectionSpace *)space

    返回指定保护空间的默认凭据。如果没有则返回nil;


  • - (void)setDefaultCredential:(NSURLCredential *)credential forProtectionSpace:(NSURLProtectionSpace *)space

    给指定保护空间的设置默认凭据,如果仓库在指定的保护空间中不包含凭据,那么此证书将被添加。

Adding and Removing Credentials
  • - (void)removeCredential:(NSURLCredential *)credential forProtectionSpace:(NSURLProtectionSpace *)space

    从仓库中删除指定安全空间的指定证书;


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

    使用给定的选项来从仓库中删除指定安全空间的指定证书;

    options:包含删除凭证时要考虑的选项的字典。只用当证书的persistence为NSURLCredentialPersistenceSynchronizable才会都用到此选项;当删除具有此策略的NSURLCredential对象时,所有包含此凭据的设备上的凭据都将被删除。


  • - (void)setCredential:(NSURLCredential *)credential forProtectionSpace:(NSURLProtectionSpace *)space

    给指定安全空间添加证书;如果已经存在相同用户名的证书,则替换掉

Retrieving Credentials
  • @property(readonly, copy) NSDictionary *> *allCredentials

    所有可用的安全空间的证书;
    字典有NSURLProtectionSpace对象的键和其对应的值;值也为字典,其中键是用户名字符串,值是相应的NSURLCredential对象。


  • - (NSDictionary *)credentialsForProtectionSpace:(NSURLProtectionSpace *)space

    返回指定安全空间的所有证书组成的字典;

Constants
  • NSString *const NSURLCredentialStorageRemoveSynchronizableCredentials

    相应的值是一个NSNumber对象,表示一个布尔值,指示是否应该删除包含NSURLCredentialPersistenceSynchronizable属性的凭据。
    如果密钥丢失或值为@NO,则不会尝试删除此凭证。

Notifications
  • const NSNotificationName NSURLCredentialStorageChangedNotification

    当存储的凭据被更改时发送此通知。通知对象是NSURLCredentialStorage实例。 此通知不包含用户信息字典。

Instance Methods

这部分方法定义在NSURLSessionTaskAdditions分类总,苹果文档均没有解释,以下均是自己YY

  • - (void)getCredentialsForProtectionSpace:(NSURLProtectionSpace *)protectionSpace task:(NSURLSessionTask *)task completionHandler:(void (^)(NSDictionary *credentials))completionHandler

    获取指定安全空间,指定任务里的所有证书,并在获取到后调用completionHandler;


  • - (void)getDefaultCredentialForProtectionSpace:(NSURLProtectionSpace *)space task:(NSURLSessionTask *)task completionHandler:(void (^)(NSURLCredential *credential))completionHandler

    获取指定安全空间,指定任务里默认证书,并在获取到后调用completionHandler;


  • - (void)removeCredential:(NSURLCredential *)credential forProtectionSpace:(NSURLProtectionSpace *)protectionSpace options:(NSDictionary *)options task:(NSURLSessionTask *)task

    根据指定options,移除指定空间,指定任务的指定证书


  • - (void)setCredential:(NSURLCredential *)credential forProtectionSpace:(NSURLProtectionSpace *)protectionSpace task:(NSURLSessionTask *)task

    给指定空间,指定任务添加指定的证书;


  • - (void)setDefaultCredential:(NSURLCredential *)credential forProtectionSpace:(NSURLProtectionSpace *)protectionSpace task:(NSURLSessionTask *)task

    给指定空间,指定任务添加指定的默认证书;

你可能感兴趣的:(NSURLCredentialStorage官方文档阅读)