Cordova-plugin-secure-storage 使用教程

Cordova-plugin-secure-storage 使用教程

cordova-plugin-secure-storageSecure storage plugin for Apache Cordova项目地址:https://gitcode.com/gh_mirrors/co/cordova-plugin-secure-storage

1. 项目的目录结构及介绍

cordova-plugin-secure-storage/
├── src/
│   ├── android/
│   ├── ios/
│   ├── blackberry10/
│   ├── wp8/
│   └── windows/
├── www/
│   └── SecureStorage.js
├── plugin.xml
├── package.json
└── README.md
  • src/: 包含各个平台的实现代码。
    • android/: Android 平台的实现代码。
    • ios/: iOS 平台的实现代码。
    • blackberry10/: BlackBerry 10 平台的实现代码。
    • wp8/: Windows Phone 8 平台的实现代码。
    • windows/: Windows 平台的实现代码。
  • www/: 包含插件的 JavaScript 接口文件 SecureStorage.js
  • plugin.xml: 插件的配置文件,定义了插件的名称、版本、依赖等信息。
  • package.json: 插件的 npm 包配置文件,包含版本、依赖等信息。
  • README.md: 项目的说明文档。

2. 项目的启动文件介绍

项目的启动文件主要是 www/SecureStorage.js,这个文件定义了插件的 JavaScript 接口。以下是 SecureStorage.js 的主要内容:

var exec = require('cordova/exec');

var SecureStorage = function() {};

SecureStorage.prototype.get = function(successCallback, errorCallback, service, key) {
    exec(successCallback, errorCallback, "SecureStorage", "get", [service, key]);
};

SecureStorage.prototype.set = function(successCallback, errorCallback, service, key, value) {
    exec(successCallback, errorCallback, "SecureStorage", "set", [service, key, value]);
};

SecureStorage.prototype.remove = function(successCallback, errorCallback, service, key) {
    exec(successCallback, errorCallback, "SecureStorage", "remove", [service, key]);
};

module.exports = new SecureStorage();
  • get: 获取存储的值。
  • set: 设置存储的值。
  • remove: 删除存储的值。

3. 项目的配置文件介绍

plugin.xml

plugin.xml 是 Cordova 插件的配置文件,定义了插件的名称、版本、依赖等信息。以下是 plugin.xml 的主要内容:

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
        id="cordova-plugin-secure-storage"
        version="3.0.1">
    <name>SecureStorage</name>
    <js-module name="SecureStorage" src="www/SecureStorage.js">
        <clobbers target="SecureStorage" />
    </js-module>
    <platform name="android">
        <config-file target="res/xml/config.xml" parent="/*">
            <feature name="SecureStorage">
                <param name="android-package" value="com.crypho.plugins.SecureStorage"/>
            </feature>
        </config-file>
        <source-file src="src/android/SecureStorage.java" target-dir="src/com/crypho/plugins"/>
    </platform>
    <platform name="ios">
        <config-file target="config.xml" parent="/*">
            <feature name="SecureStorage">
                <param name="ios-package" value="SecureStorage"/>
            </feature>
        </config-file>
        <header-file src="src/ios/SecureStorage.h"/>
        <source-file src="src/ios/SecureStorage.m"/>
    </platform>
    <!-- 其他平台的配置 -->
</plugin>
  • id: 插件的唯一标识符。
  • version: 插件的版本号。
  • js-module: 定义 JavaScript 模块。
  • platform: 定义各个平台的配置。

package.json

package.json 是 npm 包的配置文件,包含版本、依赖等信息。以下是 package.json 的主要内容:

{
  "name": "cordova-

cordova-plugin-secure-storageSecure storage plugin for Apache Cordova项目地址:https://gitcode.com/gh_mirrors/co/cordova-plugin-secure-storage

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

房栩曙Evelyn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值