You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS端Matrix SDK启用加密崩溃,报错缺少依赖如何解决?

iOS端Matrix SDK启用加密时崩溃:Missing required dependencies 解决方法

问题场景

在iOS端使用Matrix SDK启用加密功能时触发崩溃,错误提示:

[MXCryptoV2Factory] buildCrypto(session:migrationProgress:success:failure:): Missing required dependencies

相关代码:

let credentials = MXCredentials(homeServer: "http://matrix.org",
                                userId: "@your_user_id:matrix.org",
                                accessToken: "your_access_token")

// Create a matrix client
let mxRestClient = MXRestClient(credentials: credentials, unrecognizedCertificateHandler: nil)

// Create a matrix session
let session = MXSession(matrixRestClient: mxRestClient) 

// enable crypto

if session.crypto == nil {
        session.enableCrypto(true) { response in
            if response.isSuccess {
                print("crypto is enabled")
            } else {
                print("crypto is not enabled yet")
            }
        }
    }

解决方法

  • 确认加密依赖已正确集成
    Matrix SDK的加密功能依赖额外组件(如libolm),如果用CocoaPods管理依赖,需确保Podfile中包含加密子spec:
pod 'MatrixSDK/Crypto'

执行pod install重新安装依赖;如果是手动集成,要确保MXCryptoV2相关框架及libolm库已添加到项目中。

  • 先完成Session初始化再启用加密
    直接创建Session后就调用enableCrypto会因Session未完成初始化导致依赖缺失,需先调用session.start()等待Session就绪:
session.start { [weak self] response in
    guard let self = self else { return }
    guard response.isSuccess else {
        print("Session启动失败: \(response.error?.localizedDescription ?? "未知错误")")
        return
    }
    
    if self.session.crypto == nil {
        self.session.enableCrypto(true) { cryptoResponse in
            if cryptoResponse.isSuccess {
                print("加密功能已启用")
            } else {
                print("加密功能启用失败: \(cryptoResponse.error?.localizedDescription ?? "未知错误")")
            }
        }
    }
}
  • 更新到最新版Matrix SDK
    旧版本SDK可能存在依赖兼容性问题,通过CocoaPods更新到最新稳定版:
pod update MatrixSDK

内容的提问来源于stack exchange,提问作者DURGA_PRASAD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 09:13:01