前言
之前雖然經(jīng)常有在做筆記的習(xí)慣吓蘑,但是往往寫的很零散不便于記憶和回顧,所以想要通過寫文章的方式將之前的筆記做一個整理。
第三方框架UIKeyChainStore使用
1.使用場景
在app開發(fā)過程中通常會涉及到敏感信息的保存磨镶,ios給我們提供了keychain來將數(shù)據(jù)保存到鑰匙串中(例如手游溃蔫,當(dāng)把游戲卸載后,我們再次安裝的時候我們希望不用輸入用戶名和密碼就能直接登錄的時候就可以用到UICKeyChainStore里面的存儲方法來進(jìn)行密碼保存)
2.使用前準(zhǔn)備
1.pod 導(dǎo)入UICKeyChainStore庫 (或者將UICKeyChainStore.h 和UICKeyChainStore.m導(dǎo)入工程)
2.導(dǎo)入 Security.framework庫
3.基本用法
1.存儲
UICKeyChainStore *keychain = [UICKeyChainStore keyChainStoreWithService:@"通常是bundleid"];
keychain[@"password"] =? @"xxxxxxxxx";
2.取值
UICKeyChainStore *keychain = [UICKeyChainStore keyChainStoreWithService:@"通常是bundleid"];
NSString *password =? [keychainStore stringForKey:@"password"];
4.下載地址
UICKeyChainStore? 地址:https://github.com/kishikawakatsumi/UICKeyChainStore
5.多個App之間共享同一個設(shè)備唯一標(biāo)識符
一次性創(chuàng)建CFUUID+持久性存儲(用到UIKeyChainStore)
1.設(shè)備唯一標(biāo)識符UUID (ios 6 之后蘋果不再提供通過uniqueIdentifier去獲取設(shè)備的UUID琳猫,因此這里我們通過CFUUID作為設(shè)備唯一標(biāo)識符)
FCUUID提供的類方法(使用條件多個App必須是同一個證書發(fā)布的)https://github.com/fabiocaccamo/FCUUID
//changes each time (no persistent)(每次運行都會變化)
+(NSString*)uuid;
//changes each time (no persistent), but allows to keep in memory more temporary uuids()
+(NSString*)uuidForKey:(id)key;
//changes each time the app gets launched (persistent to session)每次運行應(yīng)用都會變
+(NSString*)uuidForSession;
//changes each time the app gets installed (persistent to installation)每次重新安裝的時候會變化
+(NSString*)uuidForInstallation;
//changes each time all the apps of the same vendor are uninstalled (this works exactly as identifierForVendor)(卸載重裝后會變化)
+(NSString*)uuidForVendor;
//changes only on system reset, this is the best replacement to the good old udid (persistent to device)+(抹掉iphone后會變化適合作為設(shè)備唯一標(biāo)識符)
(NSString*)uuidForDevice;
如何開啟keychain sharing(鑰匙串共享)
>點擊capabilities-->打開keychain sharing-->Xcode會自動幫你生成entitlements文件-->分別在兩個不同的項目中的keychain sharing中添加所有App的(開發(fā)者id + bundle identifier)->大功告成伟叛。通過真機(jī)測試,證實該方案可行脐嫂。