# 错误排查 (/zh-CN/realtime-media/rtm/build/troubleshooting/swift)
> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).
## 开启本地日志 [#开启本地日志-7]
当你的应用处于开发、测试阶段时,你可能需要 SDK 输出更详细的信息来定位并修复问题。你可以在初始化 RTM 实例的时候通过设置 `AgoraRtmClientConfig` 中的 `AgoraRtmLogConfig` 来开启日志输出并设置日志信息等级,之后即可在 IDE 中查看日志信息。
```swift
let config = AgoraRtmClientConfig(appId: "yourAppId", userId: "uniqueUserId")
config.logConfig = AgoraRtmLogConfig();
config.logConfig?.filePath = "your path"
config.logConfig?.fileSizeInKB = 512
config.logConfig?.level = .error
```
`level` 字段可以设置为 `info`、`warn`、`error`、`fatal`、`none` 五个等级之一,其中 `info` 输出最详细的日志信息,`none` 不输出日志信息。
:::info[信息]
当你的应用上线时,请将日志信息等级设置为 `info`。
:::
## 错误码对照表 [#错误码对照表-7]
在调用 RTM iOS/Swift API 时,如果发生错误,SDK 会执行 `completion` 回调并且返回一个 `AgoraRtmErrorInfo` 类型的 `errorInfo` 返回值:
| 属性 | 类型 | 描述 |
| ---- | ------- | --------- |
| `errorCode` | `AgoraRtmErrorCode` | 本次操作错误码。 |
| `reason` | NSString | 本次操作出错原因。 |
| `operation` | NSString | 本次操作类型。 |
其中,`errorCode` 和 `reason` 属性分别报告错误码和错误描述,你可以在下面的表格中寻找解决方法:
| 错误码 | 错误描述 | 原因及解决方法 |
| --- | --- | --- |
| `0` | `ok` | 正确调用。 |
| `-10001` | `notInitialized` | SDK 未初始化。请创建 `AgoraRtmClientKit` 实例后再执行其他操作。 |
| `-10002` | `notLogin` | 用户未登录 RTM 系统、掉线超时或者主动退出登录后调用 API。请先登录 RTM 系统。 |
| `-10003` | `invalidAppId` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-4-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-4-2-5) |
| `-10005` | `invalidToken` | 无效 Token。检查 Token Provider 是否生成 RTM Token。 |
| `-10006` | `invalidUserId` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-6-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-6-2-5) |
| `-10007` | `initServiceFailed` | SDK 初始化失败。请重新创建 `AgoraRtmClientKit` 实例。 |
| `-10008` | `invalidChannelName` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-8-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-8-2-5) |
| `-10009` | `tokenExpired` | Token 过期失效。你需要调用 `renewToken` 重新获取 Token。 |
| `-10010` | `loginNoServerResources` | 服务器资源受限。建议重新登录。 |
| `-10011` | `loginTimeout` | 登录超时。你需要检查当前网络是否稳定并切换到稳定网络环境中。如果你的网络处于内网环境,请检查你的防火墙是否配置了正确的域名和端口,详见[防火墙白名单设置](/zh-CN/realtime-media/rtm/build/rtm-initialization/application-setup#防火墙白名单设置)。 |
| `-10012` | `loginRejected` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-12-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-12-2-5) |
| `-10013` | `loginAborted` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-13-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-13-2-5) |
| `-10014` | `invalidParameter` | 参数无效。检查你填写的参数是否正确。 |
| `-10015` | `loginNotAuthorized` | 没有 RTM 服务权限。检查控制台是否开通 RTM 服务。 |
| `-10016` | `loginInconsistentAppId` | App ID 不一致。检查初始化、登录、加入频道的 App ID 是否一致。 |
| `-10017` | `duplicateOperation` | 重复操作。 |
| `-10018` | `instanceAlreadyReleased` | 重复调用 `destroy` 方法释放 `AgoraRtmClientKit` 实例或重复调用 `destroy` 释放 `AgoraRtmStreamChannel` 实例。 |
| `-10019` | `invalidChannelType` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-19-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-19-2-5) |
| `-10020` | `invalidEncryptionParameter` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-20-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-20-2-5) |
| `-10021` | `operationRateExceedLimitation` | API 调用频率超过限制。各 API 的配额见[API 使用限制](/zh-CN/realtime-media/rtm/reference/usage-limits-and-errors/api-limits)。 |
| `-10022` | `serviceNotSupport` | 服务类型不支持。请检查你在 `AgoraRtmServiceType` 中设置的服务类型是否正确。该错误码仅适用于私有化部署功能。 |
| `-10023` | `loginCanceled` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-23-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-23-2-5) |
| `-10024` | `invalidPrivateConfig` | 私有化部署参数设置无效。请检查你在 `AgoraRtmPrivateConfig` 中设置的服务类型和服务器地址是否有效。 |
| `-10025` | `notConnected` | 未连接 RTM 服务器。请确认服务连接可用后再调用相关 API。 |
| `-10026` | `renewTokenTimeout` | 更新 Token 超时。 |
| `-11001` | `channelNotJoined` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-27-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-27-2-4) |
| `-11002` | `channelNotSubscribed` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-28-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-28-2-5) |
| `-11003` | `channelExceedTopicUserLimitation` | 订阅该 Topic 人数超出限制。 |
| `-11004` | `channelReused` | 共频道模式下,RTM 释放了 Stream Channel。 |
| `-11005` | `channelInstanceExceedLimitation` | 创建的频道数量或订阅的频道数量超出限制。详见 [API 调用限制](/zh-CN/realtime-media/rtm/reference/usage-limits-and-errors/api-limits)。 |
| `-11006` | `channelInErrorState` | 频道不可用。请重新创建 Stream Channel 或重新订阅 Message Channel。 |
| `-11007` | `channelJoinFailed` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-33-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-33-2-4) |
| `-11008` | `channelInvalidTopicName` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-34-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-34-2-4) |
| `-11009` | `channelInvalidMessage` | 无效消息。检查消息类型是否合法,RTM 只支持字符串或二进制类型消息。 |
| `-11010` | `channelMessageLengthExceedLimitation` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-36-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-36-2-4) |
| `-11011` | `channelInvalidUserList` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-37-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-37-2-4) |
| `-11012` | `channelNotAvailable` | Stream Channel 功能未开通,当前不可用。检查控制台是否已开启 Stream Channel 功能。 |
| `-11013` | `channelTopicNotSubscribed` | 未订阅该 Topic。 |
| `-11014` | `channelExceedTopicLimitation` | Topic 数量超出限制。 |
| `-11015` | `channelJoinTopicFailed` | 加入该 Topic 失败。检查已加入 Topic 数量是否超出限制。 |
| `-11016` | `channelTopicNotJoined` | 未加入该 Topic。未加入 Topic 就发送消息,你需要先加入 Topic。 |
| `-11017` | `channelTopicNotExist` | 该 Topic 不存在。检查 Topic 名是否错误。 |
| `-11018` | `channelInvalidTopicMeta` | Topic 中的 `meta` 参数无效。检查 `meta` 参数是否超出 256 字节的限制。 |
| `-11019` | `channelSubscribeTimeout` | 频道订阅超时。检查连接是否断开。 |
| `-11020` | `channelSubscribeTooFrequent` | 频道订阅操作太频繁。请确保 5 秒内对同一频道的订阅操作不超过 2 次。 |
| `-11021` | `channelSubscribeFailed` | 频道订阅失败。检查已订阅频道数量是否超出限制。 |
| `-11022` | `channelUnsubscribeFailed` | 取消频道订阅失败。检查连接是否断开。 |
| `-11023` | `channelEncryptMessageFailed` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-49-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-49-2-4) |
| `-11024` | `channelPublishMessageFailed` | 消息发布失败。检查连接是否断开。 |
| `-11026` | `channelPublishMessageTimeout` | 消息发布超时。检查连接是否断开。 |
| `-11027` | `channelNotConnected` | SDK 与 RTM 服务器断开连接。请重新登录。 |
| `-11028` | `channelLeaveFailed` | 离开频道失败。检查连接是否断开。 |
| `-11029` | `channelCustomTypeLengthOverflow` | Custom type 长度溢出。`customType` 字段长度需要在 32 个字符以内。 |
| `-11030` | `channelInvalidCustomType` | `customType` 字段无效。检查 `customType` 字段是否包含非法字符。 |
| `-11031` | `channelUnsupportedMessageType` | 消息类型不支持。 |
| `-11032` | `channelPresenceNotReady` | Presence 服务未就绪。请重新加入 Stream Channel 或重新订阅 Message Channel。 |
| `-11033` | `channelReceiverOffline` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-58-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-58-2-4) |
| `-11034` | `channelJoinCanceled` | 加入频道操作已取消。调用 `join` 方法后,如果你在收到调用结果之前再次调用该方法,则前一次的调用操作会被取消,SDK 会执行后一次的调用。 |
| `-11035` | `channelReceiverOfflineButMessageStoreSucceeded` | 接收端已下线,且消息成功保存至历史消息,待接收端上线后可查看消息。 |
| `-11036` | `channelReceiverOfflineAndMessageStoreFailed` | 接收端已下线,但历史消息存储失败。 |
| `-11037` | `channelMessageDeliveredButStoreFailed` | 消息成功发送到接收端,但历史消息存储失败。 |
| `-11040` | `channelSubscribeCanceled` | 订阅频道操作已取消。调用 `subscribe` 后,如果在收到结果前调用 `unsubscribe` 打断订阅,会返回该错误。 |
| `-12001` | `storageOperationFailed` | Storage 操作失败。 |
| `-12002` | `storageMetadataItemExceedLimitation` | Storage Metadata Item 数量超出限制。 |
| `-12003` | `storageInvalidMetadataItem` | 无效 Metadata Item。 |
| `-12004` | `storageInvalidArgument` | 无效参数。 |
| `-12005` | `storageInvalidRevision` | 无效 Revision 参数。 |
| `-12006` | `storageMetadataLengthOverflow` | Metadata 长度溢出。 |
| `-12007` | `storageInvalidLockName` | 无效 Lock 名称。 |
| `-12008` | `storageLockNotAcquired` | 未获取该 Lock。 |
| `-12009` | `storageInvalidKey` | 无效 Metadata 键。 |
| `-12010` | `storageInvalidValue` | 无效 Metadata 值。 |
| `-12011` | `storageKeyLengthOverflow` | Metadata 键长度溢出。 |
| `-12012` | `storageValueLengthOverflow` | Metadata 值长度溢出。 |
| `-12013` | `storageDuplicateKey` | 重复的 Metadata Item 键。 |
| `-12014` | `storageOutdatedRevision` | Metadata Item 中的 Revision 过时或 Key 不存在。 |
| `-12015` | `storageNotSubscribe` | 未订阅该频道。 |
| `-12016` | `storageInvalidMetadataInstance` | Metadata 实例不存在。请创建 Metadata 实例。 |
| `-12017` | `storageSubscribeUserExceedLimitation` | 订阅用户 Metadata 数量超出限制。 |
| `-12018` | `storageOperationTimeout` | Storage 操作超时。 |
| `-12019` | `storageNotAvailable` | Storage 服务不可用。 |
| `-13001` | `presenceNotConnected` | 用户未连接到系统。 |
| `-13002` | `presenceNotWritable` | Presence 服务不可用。 |
| `-13003` | `presenceInvalidArgument` | 无效参数。 |
| `-13004` | `presenceCacheTooManyStates` | 加入频道前缓存的临时用户状态超出限制。详见 [API 调用限制](/zh-CN/realtime-media/rtm/reference/usage-limits-and-errors/api-limits)。 |
| `-13005` | `presenceStateCountOverflow` | 临时用户状态键/值对数量超出限制。详见 [API 调用限制](/zh-CN/realtime-media/rtm/reference/usage-limits-and-errors/api-limits)。 |
| `-13006` | `presenceInvalidStateKey` | 无效状态键。 |
| `-13007` | `presenceInvalidStateValue` | 无效状态值。 |
| `-13008` | `presenceStateKeySizeOverflow` | 状态键长度溢出。 |
| `-13009` | `presenceStateValueSizeOverflow` | 状态值长度溢出 |
| `-13010` | `presenceStateDuplicateKey` | 重复的状态键。 |
| `-13011` | `presenceUserNotExist` | 该用户不存在。 |
| `-13012` | `presenceOperationTimeout` | Presence 操作超时。 |
| `-13013` | `presenceOperationFailed` | Presence 操作失败。 |
| `-13014` | `presenceInactive` | Presence 服务未开启或当前不可用。请检查声网控制台是否已开启 Presence 服务开关;未开启时,依赖该服务的 Presence API 和订阅选项不可用。 |
| `-13015` | `presencePendingRequestCancelled` | Presence 待处理请求已取消。调用 Presence 相关 API 后,如果请求完成前被取消,会返回该错误。 |
| `-13016` | `presencePendingRequestExceedLimitation` | Presence 待处理请求数量超过限制。请等待已有请求完成后重试。 |
| `-14001` | `lockOperationFailed` | Lock 操作失败。 |
| `-14002` | `lockOperationTimeout` | Lock 操作超时。 |
| `-14003` | `lockOperationPerforming` | Lock 操作进行中。 |
| `-14004` | `lockAlreadyExist` | Lock 已存在。 |
| `-14005` | `lockInvalidName` | 无效 Lock 名。 |
| `-14006` | `lockNotAcquired` | 未获取该 Lock。 |
| `-14007` | `lockAcquireFailed` | 获取该 Lock 失败。 |
| `-14008` | `lockNotExist` | 该 Lock 不存在。 |
| `-14009` | `lockNotAvailable` | Lock 服务不可用。 |
| `-15001` | `historyOperationFailed` | 历史消息的操作失败。 |
| `-15002` | `historyInvalidTimestamp` | 历史消息的时间戳无效。 |
| `-15003` | `historyOperationTimeout` | 历史消息的操作超时。 |
| `-15004` | `historyOperationNotPermitted` | 没有权限进行历史消息的操作。 |
| `-15005` | `historyNotAvailable` | 历史消息服务不可用。 |
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-4-2 details**
无效 App ID:
- 检查 App ID 是否错误。
- 检查 App ID 是否开通了 RTM 服务。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-6-2 details**
无效用户 ID:
- 检查用户 ID 是否为空。
- 检查用户 ID 是否包含非法字符。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-8-2 details**
无效频道名称:
- 检查频道名是否为空。
- 检查频道名是否包含非法字符。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-12-2 details**
SDK 被服务器拒绝登录:
- 检查 App ID 是否开通 RTM 服务。
- 检查 Token 或 `userId` 是否被封禁。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-13-2 details**
由于未知问题 SDK 登录中断:
- 检查当前网络是否稳定,切换到稳定网络环境中。
- 当前 `userId` 在其他端登录。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-19-2 details**
频道类型无效。SDK 仅支持如下频道类型,请填写正确的值:
- `message`: Message Channel
- `stream`: Stream Channel
- `user`: User Channel
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-20-2 details**
消息加密参数无效。
- 检查生成的加密密钥是否为字符串类型。
- 检查生成的加密盐是否为字节数组类型,长度是否为 32 字节。
- 检查加密方式与加密密钥、加密盐是否匹配。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-23-2 details**
登录操作已取消。可能原因如下:
- 调用 `login` 方法后,如果你在收到调用结果之前再次调用该方法,则前一次的调用操作会被取消,SDK 会执行后一次的调用。
- 还未成功登录就调用 `logout` 方法登出。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-27-2 details**
用户未加入该频道:
- 用户不在线、已离线或未加入该频道
- 检查 `userId` 是否拼写错误。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-28-2 details**
用户未订阅该频道:
- 用户不在线、已离线或未加入该频道
- 检查 `userId` 是否拼写错误。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-33-2 details**
加入该频道失败:
- 检查已加入频道数量是否超限。
- 检查频道名是否非法。
- 检查网络是否断开连接。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-34-2 details**
无效 Topic 名:
- 检查 Topic 名是否包含非法字符。
- 检查 Topic 名是否为空。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-36-2 details**
消息长度超出限制。检查消息负载大小是否超限:
- Message Channel 单个消息包小于 32 KB。
- Stream Channel 单个消息包小于 1 KB。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-37-2 details**
无效用户列表:
- 检查用户列表是否为空
- 检查用户列表是否包含非法项。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-49-2 details**
消息加密失败:
- 检查加密密钥是否有效。
- 检查加密盐是否有效。
- 检查加密方式与加密密钥、加密盐是否匹配。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-58-2 details**
发送用户消息时,远端用户不在线:
- 检查在调用方法时设置的用户 ID 是否正确。
- 检查远端用户是否登录系统并处于在线状态。
## 联系我们 [#联系我们-7]
如果以上措施都为未能解决你的故障,或者你需要解决方案的支持,请将你的需求整理出来并通过邮箱发送到:rtm-support@agora.io。我们会在收到邮件的第一时间与你取得联系。