ios 開發(fā)筆記---UIKeyChainStore使用

前言

之前雖然經(jīng)常有在做筆記的習(xí)慣,但是往往寫的很零散不便于記憶和回顧,所以想要通過寫文章的方式將之前的筆記做一個整理。

第三方框架UIKeyChainStore使用

1.使用場景

在app開發(fā)過程中通常會涉及到敏感信息的保存,ios給我們提供了keychain來將數(shù)據(jù)保存到鑰匙串中(例如手游,當把游戲卸載后,我們再次安裝的時候我們希望不用輸入用戶名和密碼就能直接登錄的時候就可以用到UICKeyChainStore里面的存儲方法來進行密碼保存)

2.使用前準備

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è)備唯一標識符

一次性創(chuàng)建CFUUID+持久性存儲(用到UIKeyChainStore)

1.設(shè)備唯一標識符UUID (ios 6 之后蘋果不再提供通過uniqueIdentifier去獲取設(shè)備的UUID,因此這里我們通過CFUUID作為設(shè)備唯一標識符)

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è)備唯一標識符)

(NSString*)uuidForDevice;

如何開啟keychain sharing(鑰匙串共享)

>點擊capabilities-->打開keychain sharing-->Xcode會自動幫你生成entitlements文件-->分別在兩個不同的項目中的keychain sharing中添加所有App的(開發(fā)者id + bundle identifier)->大功告成。通過真機測試,證實該方案可行。



最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 親愛的莫名朋友: 請原諒我以這樣的稱呼和這樣的方式和您交流。 昨天,在演講結(jié)束的互動環(huán)節(jié),我收到您托主持人遞來的便...
    草木土石閱讀 267評論 0 0

友情鏈接更多精彩內(nèi)容