更新记录
1.0.0(2025-02-14)
iOS KeyChain管理器(钥匙串)
一般用于:
1、保存UUID/游客登陆
(本地随机生成一个UUID保存到KeyChain即可,卸载重装也可以读取到,传统方式使用IDFA/IDFV/设备id 作为游客登陆 有审核风险)
2、用户 记住用户名、密码
3、保存少量JSON数据:如用户信息,或者简易的JSON存档
4、保存二进制数据:少量的二进制数据 转成 Base64后保存进去
(本插件提供的是KeyChain的 读、写、删 操作,以上功能不属于本插件的功能范围)
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
HBuilderX 4.31,Android:不支持,iOS:9,HarmonyNext:不支持 |
× |
× |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
鸿蒙元服务 |
× |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
× |
× |
× |
× |
× |
× |
× |
× |
× |
请试用满意后再购买
简易示例
<script>
// 引入包
import { keychain_saveText,keychain_loadText,keychain_delete } from '../../uni_modules/aper-keychainmanager'
export default {
data() {
return {
testjson01: '',
}
},
methods: {
readkey(){//读取
this.testjson01 = keychain_loadText("com.aper.demo","testjson01");
//两个参数分别是 :service(不一定要是包名,随你写什么都行),key,不存在则返回""
},
savekey(){//保存
keychain_saveText("com.aper.demo","testjson01",`{"hello":"world","testarr":[1,2,3,4]}`
},
deletekey(){//删除
keychain_delete("com.aper.demo","testjson01")
}
}
}
</script>
完整示例
<template>
<view>
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">testjson01: {{testjson01}}</text>
<text class="title">readres1: {{readres1}}</text>
<text class="title">readres2: {{readres2}}</text>
<button @click="savekey">保存</button>
<button @click="readkey">读取</button>
<button @click="deletekey">删除</button>
<text class="title">{{notice}}</text>
</view>
</view>
</template>
<script>
import { keychain_saveText,keychain_loadText,keychain_delete } from '../../uni_modules/aper-keychainmanager'
export default {
data() {
return {
testjson01: '',
readres1: '',
readres2: '',
notice:''
}
},
onLoad() {
},
methods: {
//读取
readkey(){
this.testjson01 = keychain_loadText("com.aper.demo","testjson01");
//两个参数分别是 :service(不一定要是包名,随你写什么都行),key,不存在则返回""
this.readres1 = keychain_loadText("userinfo","username");
this.readres2 = keychain_loadText("userinfo","password");
this.notice = "读取完成"
},
//保存
savekey(){
//返回的是bool
if(keychain_saveText("com.aper.demo","testjson01",`{"hello":"world","testarr":[1,2,3,4]}`)){
console.log("com.aper.demo -> testjson01 保存成功")
}else{
console.log("com.aper.demo -> testjson01 保存失败")
}
//三个参数分别是 :service(不一定要是包名,随你写什么都行),key,value
keychain_saveText("userinfo","username","testuser");
keychain_saveText("userinfo","password","testpass");
this.notice = "保存完成,读取试试呢!卸载app也不会失效哦"
},
//删除
deletekey(){
//返回的是bool
if(keychain_delete("com.aper.demo","testjson01")){
console.log("com.aper.demo -> testjson01 删除成功,删除完成后可以读取试一下")
}else{
console.log("com.aper.demo -> testjson01 删除失败")
}
keychain_delete("userinfo","username")
keychain_delete("userinfo","password")
this.notice = "删除完成,读取试试呢!"
}
}
}
</script>
<style>
.logo {
height: 100px;
width: 100px;
margin: 100px auto 25px auto;
}
.title {
font-size: 18px;
color: #8f8f94;
text-align: center;
}
</style>