Skip to content

Conversation

@iMacHumphries
Copy link

This should really be extended to allow further configuration/control of the keychain interface, but for now this solves the problem I'm having and I wanted to share.

Example usage:

var keychain = null
func _ready():
    if Engine.has_singleton("Keychain"):
        keychain = Engine.get_singleton("Keychain")
        
        keychain.set_string("username", "knight123")
        var username = keychain.get_string("username")
        print("Stored username: ", username)
        keychain.delete_key("username")

Test plan

        class_name Keychain extends node # Singleton
        
        extends Node

var _keychain

func _ready() -> void:
	if Engine.has_singleton("Keychain"):
		_keychain = Engine.get_singleton("Keychain")

func set_string(key: String, value: String) -> void:
	if _keychain:
		_keychain.set_string(key, value)

func get_string(key: String) -> String:
	if _keychain:
		return _keychain.get_string(key)

func delete_key(key: String) -> void:
	if _keychain:
		_keychain.delete_key(key)
        
        #################
        
	print("Keychain test")
	var result = Keychain.get_string("test")
	print("1. Get test:", result)
	if not result:
		Keychain.set_string("test", "1")
		print("2. Save test:", Keychain.get_string("test"))
  1. Run on new application. Result:
    Keychain test

  2. Get test:

  3. save test: 1

  4. Delete app from iPhone and run again. Result:
    Keychain test

  5. Get test: 1

@jackchapm
Copy link

+1, hoping to bring some attention to this PR as it seems like a common enough task that a first party plugin should be made for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants