Overview
KlugKeychain stores small values, such as flags, tokens or IDs, in the keychain of iOS and macOS. Unlike normal app storage, the keychain keeps these values when the app is uninstalled and installed again.
That makes it a durable anchor for things an app needs to remember across reinstalls, for example whether a device has already used a free trial, or whether an account was deleted before.
KlugKeychain is in daily use in our apps, our proof of concept.
Features
- Self-contained: one ANE, no core library or dependency ANEs to add
- Store, read, check and remove values by key
- Values survive uninstalling and reinstalling the app
- Encrypted by the operating system in the system keychain
- One API for iOS and macOS
- Simple synchronous calls, no events to handle
Supported platforms
On other platforms isSupported returns false, so the same code can stay in a cross-platform app.
Getting started
Add the extension to your application descriptor:
<extensions>
<extensionID>com.klug.keychain.Keychain</extensionID>
</extensions>
On macOS the app must be signed with a keychain access group entitlement. On iOS no extra entitlement is needed.
Code examples
Three complete flows. All calls are synchronous and return at once; values are strings. Full documentation →
import com.klug.keychain.Keychain; var keychain:Keychain = Keychain.getInstance(); // iOS: always true. // macOS: true only if the app is signed with a keychain access group entitlement; // the extension checks this with a test write. // Android, Windows: false, and every call is a safe no-op. if ( !keychain.isSupported ) useLocalStorage(); // your app's fallback, e.g. a SharedObject
const TRIAL_DAYS:Number = 7; if ( keychain.has( "trialStarted" ) ) { var started:Number = Number( keychain.get( "trialStarted" ) ); var days:Number = ( new Date().time - started ) / 86400000; if ( days > TRIAL_DAYS ) showPurchaseScreen(); // your app } else { // stays in the keychain after the app is uninstalled and installed again keychain.set( "trialStarted", String( new Date().time ) ); }
// set() replaces an existing value; false = not stored if ( !keychain.set( "accountId", accountId ) ) trace( "keychain: value not stored" ); // get() returns "" when nothing is stored var id:String = keychain.get( "accountId" ); if ( id == "" ) showSignIn(); // your app // sign-out: remove what the app no longer needs; // true also when the key was already gone keychain.remove( "accountId" );
API overview
| Keychain.getInstance() | Returns the single instance. |
| isSupported | True on iOS. On macOS true when the app is signed with a keychain access group entitlement; false on other platforms. |
| set(key, value) | Stores a string, replacing an existing one. Returns true on success; false if unsupported or key or value is null. |
| get(key) | Returns the stored value, or an empty string if there is none. |
| has(key) | True if a value is stored for the key. |
| remove(key) | Removes the value. Returns true once the key no longer exists. |
| Storage | Generic password items of your app, readable after the first unlock of the device, also in the background. |
Buy KlugKeychain
A yearly licence for one AIR application, with all updates for 12 months. After payment you receive the extension, the ActionScript library and the documentation by e-mail, usually within one business day. Licence and terms
- Licence for one AIR application
- All updates for 12 months
- Answer by e-mail within 7 days
- Licence for one AIR application
- All updates for 12 months
- Answer by e-mail within 48 hours
Requirements
| AIR SDK | 51.x (HARMAN) |
| iOS | iOS 17 or later |
| macOS | macOS 11 or later |
| Signing (macOS) | Keychain access group entitlement |