Home

Awesome

Apple Keychain Key-Value Store for Unity

openupm

Key-Value Store implementation backed by macOS / iOS / tvOS / visionOS Keychain Services.

Features

Dependencies

How to install

Either:

Basic usage

using Gilzoide.KeyValueStore.AppleKeychain;
using UnityEngine;

// 1. Instantiate a GenericPasswordKeychainItemKeyValueStore with the Keychain Item attributes
var keychainItemAttributes = new GenericPasswordKeychainAttributes
{
    Service = Application.identifier,
    Description = "Small secrets used by the game",
    IsSynchronizable = true,  // synchronizable with iCloud
};

var kvs = new GenericPasswordKeychainItemKeyValueStore(keychainItemAttributes);


// 2. Set/Get/Delete values
kvs.SetBool("finishedTutorial", true);
kvs.SetString("username", "gilzoide");

Debug.Log("Checking if values exist: " + kvs.HasKey("username"));
Debug.Log("Getting values: " + kvs.GetInt("username"));
Debug.Log("Getting values with fallback: " + kvs.GetString("username", "default username"));
// Like C# Dictionary, this idiom returns a bool if the key is found
if (kvs.TryGetString("someKey", out string foundValue))
{
    Debug.Log("'someKey' exists: " + foundValue);
}

kvs.DeleteKey("someKey");


// 3. Save the updated data into the keychain
kvs.Save();


// 4. Dispose of the GenericPasswordKeychainItemKeyValueStore when done
// This ensures the native data gets released correctly
kvs.Dispose();