有没有办法保存快速的钥匙串对象和零?

时间:2016-02-11 23:55:38

标签: ios swift keychain

当我尝试保存String时,我看到我的代码失败了!或使用swift keychain的nil或AnyObject

func setSharedPrefrences()
{

    if (mainViewController != nil)
    {
        if (mainViewController.location_text != nil) {
            keychainSetSafe(mainViewController.location_text.text, key: StringConstans.keychain_lineName)
        }
    }
}

func keychainSetSafe(value: String!, key : String)
{
    if let nonNullValue = value
    {
        keychain.set(nonNullValue, forKey: key)
    }

}

func getSharedPrefrences()
{
    if (mainViewController != nil)
    {
        let gcmToken = keychain.get(StringConstans.keychain_gcmToken)
        if (gcmToken != nil) {
            mainViewController.userState.gcmToken = gcmToken
        }
    }
}

有什么方法可以存储这些类型,以便在app从bg再次移动到fg时恢复?

//
// Keychain helper for iOS/Swift.
//
// https://github.com/marketplacer/keychain-swift
//
// This file was automatically generated by combining multiple Swift source files.
//


// ----------------------------
//
// KeychainSwift.swift
//
// ----------------------------

import Security
import Foundation

/**

A collection of helper functions for saving text and data in the keychain.

*/
public class KeychainSwift

0 个答案:

没有答案