Skip to content

Latest commit

 

History

History
78 lines (52 loc) · 3.24 KB

EXAMPLES.md

File metadata and controls

78 lines (52 loc) · 3.24 KB

Examples


Use a custom service name

When creating the SimpleKeychain instance, specify a service name under which to save items. By default the bundle identifier of your app is used.

let simpleKeychain = SimpleKeychain(service: "Auth0")

Include additional attributes

When creating the SimpleKeychain instance, specify additional attributes to be included in every query.

let attributes = [kSecUseDataProtectionKeychain as String: true]
let simpleKeychain = SimpleKeychain(attributes: attributes)

Share items with other apps and extensions using an access group

When creating the SimpleKeychain instance, specify the access group that the app may share entries with.

let simpleKeychain = SimpleKeychain(accessGroup: "ABCDEFGH.com.example.myaccessgroup")

Note

For more information on access group sharing, see Sharing Access to Keychain Items Among a Collection of Apps.

Share items with other devices through iCloud synchronization

When creating the SimpleKeychain instance, set synchronizable to true to enable iCloud synchronization.

let simpleKeychain = SimpleKeychain(sychronizable: true)

Note

For more information on iCloud synchronization, check the kSecAttrSynchronizable documentation.

Restrict item accessibility based on device state

When creating the SimpleKeychain instance, specify a custom accesibility value to be used. The default value is .afterFirstUnlock.

let simpleKeychain = SimpleKeychain(accessibility: .whenUnlocked)

Note

For more information on accessibility, see Restricting Keychain Item Accessibility.

Require Touch ID / Face ID to retrieve an item

When creating the SimpleKeychain instance, specify the access control flags to be used. You can also include an LAContext instance with your Touch ID / Face ID configuration.

let context = LAContext()
context.touchIDAuthenticationAllowableReuseDuration = 10
let simpleKeychain = SimpleKeychain(accessControlFlags: .biometryCurrentSet,
                                    context: context)

Note

For more information on access control, see Restricting Keychain Item Accessibility.


Go up ⤴