mixin messenger 早期采用 fmdb 后来切换至 wcdb 沿用至今,一直比较可靠稳定,这里分享一下使用心得和功能扩展。
mixin messenger 是一个开源的端对端加密聊天软件,并且集成基于 mixin network 的多链钱包。
官网下载:
开源地址:https://github.com/mixinmessenger/ios-app
wcdb swift 是一个易用、高效、完整的移动数据库框架,基于 sqlite 和 sqlcipher 开发。
开源地址:https://github.com/tencent/wcdb/
fork 代码开源地址:https://github.com/mixinnetwork/wcdb,注意使用 xcode10.2+swift4.2 分支代码。
winq 语言集成查询适用于简单的增删改查,但是对于非常复杂的 sql 语句,用 winq 拼出来且不说代码非常多 — — 可读性和可移植性非常差,搞不懂官方为什么不支持一下。大体上读了一下源码可知 winq 也是拼 sql 语句,由于库作用域限制,只好 fork 一份改源码:
// 带参数查询 database.prepareselectsql(user.properties.id, "select id from users where id = ?", values: ["1"]) // 带参数 like 查询 database.prepareselectsql(user.properties.id, "select id from users where name like ?", values: ["%candy%"]) // 带参数更新 let updatesql = try database.prepareupdatesql(sql: "update conversations set last_message_id = (select id from messages where conversation_id = ? order by created_at desc limit 1) where conversation_id = ?") try updatesql.execute(with: [conversationid, conversationid])
需要特别注意的是如果返回 codable 数据,select 字段的顺序必须要和 codingkeys 里的顺序一致,否则数据会填充乱,用 winq 不会有这个问题。
与微信、qq、telegram 不同,mixin messenger 是端对端加密服务器不存消息,使得消息备份功能必须需要依赖客户端来完成,wcdb 没有这个需求所以不支持,可以通过扩展 sqlite 直接支持:
参考 https://github.com/mixinnetwork/wcdb/commit/83416a270116fe97fc5f8873d0ad5686a24964db 修改记录即可支持备份功能,还支持进度回调
try database.backup(withfile: path) { (remaining, pagecount) in // progress = float(pagecount - remaining) / float(pagecount) }
官方文档:关于 wcdb swift
mixin是如何实现匿名交易的?
整体来说还是比较好用,关键是可靠,而且 swift 支持的比较好,codable 支持得也很赞,欢迎交流使用经验,我的 mixin id:762532。
如对本文有疑问, 点击进行留言回复!!
网友评论