2014-09-29 51 views
1

是否可以在iOS上存儲一些信息,這些信息在應用程序被刪除時不會被刪除(如鑰匙串),也無法恢復到其他設備上?iOS Key Chain alternative無法在其他設備上恢復

據我所知 - 如果您選擇加密備份選項,鑰匙鏈將恢復到其他設備。 Does iOS keychain storage persist when restoring an app to a new device?

那麼,它在某種程度上可以保存一些數據 - 應用程序被刪除後(在重新安裝後讀它),並且它只能是它加入/創建的設備上avalible。

回答

5

有以下選項:

kSecAttrAccessibleAlwaysThisDeviceOnly 
kSecAttrAccessibleWhenUnlockedThisDeviceOnly 
kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly 

從文檔:

[...]與此屬性的商品不遷移到新設備。 [...]

我認爲他們正是你所需要的。他們在這個WWDC談話很好地解釋:

SecAccessControlRef sacObject = 
SecAccessControlCreateWithFlags(kCFAllocatorDefault, 
    kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly, 
    kSecAccessControlUserPresence, &error); 

NSData* secret = [@"top secret" dataWithEncoding:NSUTF8StringEncoding]; 
NSDictionary *query = @{ 
    (id)kSecClass: (id)kSecClassGenericPassword, 
    (id)kSecAttrService: @"myservice", 
    (id)kSecAttrAccount: @"account name here", 
    (id)kSecValueData: secret}; 

OSStatus status = SecItemAdd((CFDictionaryRef)query, nil); 

參見:https://developer.apple.com/library/ios/documentation/Security/Reference/keychainservices/index.html#//apple_ref/doc/constant_group/Keychain_Item_Accessibility_Constants

從上面的談話

https://developer.apple.com/videos/wwdc/2014/#711

用法示例