很少說了 直接貼代碼了, git
//應用名稱(保證惟一性) github
#define ServiceName @"com.小武哥.shuai" ui
//帳號 spa
#define Account @"test" orm
************】
CFUUIDRef uuid = CFUUIDCreate(NULL);assert(uuid != NULL);CFStringRef uuidStr = CFUUIDCreateString(NULL, uuid); string
NSString *strUUID = [NSString stringWithFormat:@"%@", uuidStr]; it
// 生成uuid test
[SSKeychain setPassword:strUUID forService:ServiceName account:@"myUUID"];//設置UUID 保存到鑰匙串 import
NSString *passWord = @"123456"; object
if (![SSKeychain passwordForService:ServiceName account:Account]) {//查看本地是否存儲指定 serviceName 和 account 的密碼
//若是沒設置密碼則 設定密碼 並存儲
[SSKeychain setPassword:passWord forService:ServiceName account:Account];
//打印密碼信息
NSString *retrieveuuid = [SSKeychain passwordForService:ServiceName account:Account];
NSLog(@"SSKeychain存儲顯示: 未安裝過:%@", retrieveuuid);
}else{
//曾經安裝過 則直接能打印出密碼信息(即便刪除了程序 再次安裝也會打印密碼信息) 區別於 NSUSerDefault
NSString *retrieveuuid = [SSKeychain passwordForService:ServiceName account:Account];
NSLog(@"SSKeychain存儲顯示 :已安裝過:%@", retrieveuuid);
}
NSArray *arr = [SSKeychain accountsForService:ServiceName];//獲取全部帳號
NSLog(@"%@== accountForServiceName:%@",arr,ServiceName);
NSString *mmm1 = [[arr objectAtIndex:0] objectForKey:@"acct" ] ;
NSString *mmm2 = [[arr objectAtIndex:1] objectForKey:@"acct" ] ;
NSLog(@"%@----%@--gaigaigi",mmm1,mmm2);
// 打印保存的帳號信息是否存在
*********問題 :
有可能SSKeychain.h 提示報錯,引用文件
把他拆開引用 就行了
//#import <SSKeychain/SSKeychainQuery.h>
#import "SSKeychain.h"
#import "SSKeychainQuery.h"
git地址 :https://github.com/soffes/sskeychain