# 错误排查 (/zh-CN/realtime-media/rtm/build/troubleshooting/ios) > For AI agents: see the complete documentation index at [llms.txt](/llms.txt). ## 开启本地日志 [#开启本地日志-1] 当你的应用处于开发、测试阶段时,你可能需要 SDK 输出更详细的信息来定位并修复问题。你可以在初始化 RTM 实例的时候通过设置 `AgoraRtmClientConfig` 中的 `AgoraRtmLogConfig` 来开启日志输出并设置日志信息等级,之后即可在 IDE 中查看日志信息。 ```objc showLineNumbers AgoraRtmClientConfig* rtm_cfg = [[AgoraRtmClientConfig alloc] initWithAppId:@"your_appid" userId:@"your_userid"]; AgoraRtmLogConfig* log_cfg = [[AgoraRtmLogConfig alloc] init]; log_cfg.level= AgoraRtmLogLevelError; log_cfg.filePath= @"your_path"; log_cfg.fileSizeInKB = 512; rtm_cfg.logConfig = log_cfg; ``` `level` 字段可以设置为 `AgoraRtmLogLevelInfo`、`AgoraRtmLogLevelWarn`、`AgoraRtmLogLevelError`、`AgoraRtmLogLevelFatal`、`AgoraRtmLogLevelNone` 五个等级之一,其中 `AgoraRtmLogLevelInfo` 输出最详细的日志信息,`AgoraRtmLogLevelNone` 不输出日志信息。 :::info[信息] 当你的应用上线时,请将日志信息等级设置为 `AgoraRtmLogLevelInfo`。 ::: ## 错误码对照表 [#错误码对照表-1] 在调用 RTM iOS/Swift API 时,如果发生错误,SDK 会执行 `completion` 回调并且返回一个 `AgoraRtmErrorInfo` 类型的 `errorInfo` 返回值: | 属性 | 类型 | 描述 | | ---- | ------- | --------- | | `errorCode` | `AgoraRtmErrorCode` | 本次操作错误码。 | | `reason` | NSString | 本次操作出错原因。 | | `operation` | NSString | 本次操作类型。 | 其中,`errorCode` 和 `reason` 属性分别报告错误码和错误描述,你可以在下面的表格中寻找解决方法: | 错误码 | 错误描述 | 原因及解决方法 | | --- | --- | --- | | `0` | `AgoraRtmErrorOk` | 正确调用。 | | `-10001` | `AgoraRtmErrorNotInitialized` | SDK 未初始化。请在调用 `initWithConfig` 方法初始化 RTM 实例后再执行其他操作。 | | `-10002` | `AgoraRtmErrorNotLogin` | 用户未登录 RTM 系统、掉线超时或者主动退出登录后调用 API。请先登录 RTM 系统。 | | `-10003` | `AgoraRtmErrorInvalidAppId` | [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-1) | | `-10005` | `AgoraRtmErrorInvalidToken` | 无效 Token。检查 Token Provider 是否生成 RTM Token。 | | `-10006` | `AgoraRtmErrorInvalidUserId` | [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-1) | | `-10007` | `AgoraRtmErrorInitServiceFailed` | SDK 初始化失败。请重新调用 `initWithConfig` 方法进行初始化。 | | `-10008` | `AgoraRtmErrorInvalidChannelName` | [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-1) | | `-10009` | `AgoraRtmErrorTokenExpired` | Token 过期失效。你需要调用 `renewToken` 重新获取 Token。 | | `-10010` | `AgoraRtmErrorLoginNoServerResources` | 服务器资源受限。建议重新登录。 | | `-10011` | `AgoraRtmErrorLoginTimeout` | 登录超时。你需要检查当前网络是否稳定并切换到稳定网络环境中。如果你的网络处于内网环境,请检查你的防火墙是否配置了正确的域名和端口,详见[防火墙白名单设置](/zh-CN/realtime-media/rtm/build/rtm-initialization/application-setup#防火墙白名单设置)。 | | `-10012` | `AgoraRtmErrorLoginRejected` | [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-1) | | `-10013` | `AgoraRtmErrorLoginAborted` | [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-1) | | `-10014` | `AgoraRtmErrorInvalidParameter` | 参数无效。检查你填写的参数是否正确。 | | `-10015` | `AgoraRtmErrorLoginNotAuthorized` | 没有 RTM 服务权限。检查控制台是否开通 RTM 服务。 | | `-10016` | `AgoraRtmErrorLoginInconsistentAppId` | App ID 不一致。检查初始化、登录、加入频道的 App ID 是否一致。 | | `-10017` | `AgoraRtmErrorDuplicateOperation` | 重复操作。 | | `-10018` | `AgoraRtmErrorInstanceAlreadyReleased` | 重复调用 `destroy` 方法释放 `AgoraRtmClientKit` 实例或重复调用 `destroy` 释放 `AgoraRtmStreamChannel` 实例。 | | `-10019` | `AgoraRtmErrorInvalidChannelType` | [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-1) | | `-10020` | `AgoraRtmErrorInvalidEncryptionParameter` | [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-1) | | `-10021` | `AgoraRtmErrorOperationRateExceedLimitation` | API 调用频率超过限制。各 API 的配额见[API 使用限制](/zh-CN/realtime-media/rtm/reference/usage-limits-and-errors/api-limits)。 | | `-10022` | `AgoraRtmErrorServiceNotSupport` | 服务类型不支持。请检查你在 `AgoraRtmServiceType` 中设置的服务类型是否正确。该错误码仅适用于私有化部署功能。 | | `-10023` | `AgoraRtmErrorLoginCanceled` | [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-1) | | `-10024` | `AgoraRtmErrorInvalidPrivateConfig` | 私有化部署参数设置无效。请检查你在 `AgoraRtmPrivateConfig` 中设置的服务类型和服务器地址是否有效。 | | `-10025` | `AgoraRtmErrorNotConnected` | 未连接 RTM 服务器。请确认服务连接可用后再调用相关 API。 | | `-10026` | `AgoraRtmErrorRenewTokenTimeout` | 更新 Token 超时。 | | `-11001` | `AgoraRtmErrorChannelNotJoined` | [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-1) | | `-11002` | `AgoraRtmErrorChannelNotSubscribed` | [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-1) | | `-11003` | `AgoraRtmErrorChannelExceedTopicUserLimitation` | 订阅该 Topic 人数超出限制。 | | `-11004` | `AgoraRtmErrorChannelReused` | 共频道模式下,RTM 释放了 Stream Channel。 | | `-11005` | `AgoraRtmErrorChannelInstanceExceedLimitation` | 创建的频道数量或订阅的频道数量超出限制。详见 [API 调用限制](/zh-CN/realtime-media/rtm/reference/usage-limits-and-errors/api-limits)。 | | `-11006` | `AgoraRtmErrorChannelInErrorState` | 频道不可用。请重新创建 Stream Channel 或重新订阅 Message Channel。 | | `-11007` | `AgoraRtmErrorChannelJoinFailed` | [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-1) | | `-11008` | `AgoraRtmErrorChannelInvalidTopicName` | [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-1) | | `-11009` | `AgoraRtmErrorChannelInvalidMessage` | 无效消息。检查消息类型是否合法,RTM 只支持字符串或二进制类型消息。 | | `-11010` | `AgoraRtmErrorChannelMessageLengthExceedLimitation` | [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-1) | | `-11011` | `AgoraRtmErrorChannelInvalidUserList` | [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-1) | | `-11012` | `AgoraRtmErrorChannelNotAvailable` | Stream Channel 功能未开通,当前不可用。检查控制台是否已开启 Stream Channel 功能。 | | `-11013` | `AgoraRtmErrorChannelTopicNotSubscribed` | 未订阅该 Topic。 | | `-11014` | `AgoraRtmErrorChannelExceedTopicLimitation` | Topic 数量超出限制。 | | `-11015` | `AgoraRtmErrorChannelJoinTopicFailed` | 加入该 Topic 失败。检查已加入 Topic 数量是否超出限制。 | | `-11016` | `AgoraRtmErrorChannelTopicNotJoined` | 未加入该 Topic。未加入 Topic 就发送消息,你需要先加入 Topic。 | | `-11017` | `AgoraRtmErrorChannelTopicNotExist` | 该 Topic 不存在。检查 Topic 名是否错误。 | | `-11018` | `AgoraRtmErrorChannelInvalidTopicMeta` | Topic 中的 `meta` 参数无效。检查 `meta` 参数是否超出 256 字节的限制。 | | `-11019` | `AgoraRtmErrorChannelSubscribeTimeout` | 频道订阅超时。检查连接是否断开。 | | `-11020` | `AgoraRtmErrorChannelSubscribeTooFrequent` | 频道订阅操作太频繁。请确保 5 秒内对同一频道的订阅操作不超过 2 次。 | | `-11021` | `AgoraRtmErrorChannelSubscribeFailed` | 频道订阅失败。检查已订阅频道数量是否超出限制。 | | `-11022` | `AgoraRtmErrorChannelUnsubscribeFailed` | 取消频道订阅失败。检查连接是否断开。 | | `-11023` | `AgoraRtmErrorChannelEncryptMessageFailed` | [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-1) | | `-11024` | `AgoraRtmErrorChannelPublishMessageFailed` | 消息发布失败。检查连接是否断开。 | | `-11026` | `AgoraRtmErrorChannelPublishMessageTimeout` | 消息发布超时。检查连接是否断开。 | | `-11027` | `AgoraRtmErrorChannelNotConnected` | SDK 与 RTM 服务器断开连接。请重新登录。 | | `-11028` | `AgoraRtmErrorChannelLeaveFailed` | 离开频道失败。检查连接是否断开。 | | `-11029` | `AgoraRtmErrorChannelCustomTypeLengthOverflow` | Custom type 长度溢出。`customType` 字段长度需要在 32 个字符以内。 | | `-11030` | `AgoraRtmErrorChannelInvalidCustomType` | `customType` 字段无效。检查 `customType` 字段是否包含非法字符。 | | `-11031` | `AgoraRtmErrorChannelUnsupportedMessageType` | 消息类型不支持。 | | `-11032` | `AgoraRtmErrorChannelPresenceNotReady` | Presence 服务未就绪。请重新加入 Stream Channel 或重新订阅 Message Channel。 | | `-11033` | `AgoraRtmErrorChannelReceiverOffline` | [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-1) | | `-11034` | `AgoraRtmErrorChannelJoinCanceled` | 加入频道操作已取消。调用 `joinWithOption` 方法后,如果你在收到调用结果之前再次调用该方法,则前一次的调用操作会被取消,SDK 会执行后一次的调用。 | | `-11035` | `AgoraRtmErrorChannelReceiverOfflineButMessageStoreSucceeded` | 接收端已下线,且消息成功保存至历史消息,待接收端上线后可查看消息。 | | `-11036` | `AgoraRtmErrorChannelReceiverOfflineAndMessageStoreFailed` | 接收端已下线,但历史消息存储失败。 | | `-11037` | `AgoraRtmErrorChannelMessageDeliveredButStoreFailed` | 消息成功发送到接收端,但历史消息存储失败。 | | `-11040` | `AgoraRtmErrorChannelSubscribeCanceled` | 订阅频道操作已取消。调用 `subscribe` 后,如果在收到结果前调用 `unsubscribe` 打断订阅,会返回该错误。 | | `-12001` | `AgoraRtmErrorStorageOperationFailed` | Storage 操作失败。 | | `-12002` | `AgoraRtmErrorStorageMetadataItemExceedLimitation` | Storage Metadata Item 数量超出限制。 | | `-12003` | `AgoraRtmErrorStorageInvalidMetadataItem` | 无效 Metadata Item。 | | `-12004` | `AgoraRtmErrorStorageInvalidArgument` | 无效参数。 | | `-12005` | `AgoraRtmErrorStorageInvalidRevision` | 无效 Revision 参数。 | | `-12006` | `AgoraRtmErrorStorageMetadataLengthOverflow` | Metadata 长度溢出。 | | `-12007` | `AgoraRtmErrorStorageInvalidLockName` | 无效 Lock 名称。 | | `-12008` | `AgoraRtmErrorStorageLockNotAcquired` | 未获取该 Lock。 | | `-12009` | `AgoraRtmErrorStorageInvalidKey` | 无效 Metadata 键。 | | `-12010` | `AgoraRtmErrorStorageInvalidValue` | 无效 Metadata 值。 | | `-12011` | `AgoraRtmErrorStorageKeyLengthOverflow` | Metadata 键长度溢出。 | | `-12012` | `AgoraRtmErrorStorageValueLengthOverflow` | Metadata 值长度溢出。 | | `-12013` | `AgoraRtmErrorStorageDuplicateKey` | 重复的 Metadata Item 键。 | | `-12014` | `AgoraRtmErrorStorageOutdatedRevision` | Metadata Item 中的 Revision 过时或 Key 不存在。 | | `-12015` | `AgoraRtmErrorStorageNotSubscribe` | 未订阅该频道。 | | `-12016` | `AgoraRtmErrorStorageInvalidMetadataInstance` | Metadata 实例不存在。请创建 Metadata 实例。 | | `-12017` | `AgoraRtmErrorStorageSubscribeUserExceedLimitation` | 订阅用户 Metadata 数量超出限制。 | | `-12018` | `AgoraRtmErrorStorageOperationTimeout` | Storage 操作超时。 | | `-12019` | `AgoraRtmErrorStorageNotAvailable` | Storage 服务不可用。 | | `-13001` | `AgoraRtmErrorPresenceNotConnected` | 用户未连接到系统。 | | `-13002` | `AgoraRtmErrorPresenceNotWritable` | Presence 服务不可用。 | | `-13003` | `AgoraRtmErrorPresenceInvalidArgument` | 无效参数。 | | `-13004` | `AgoraRtmErrorPresenceCacheTooManyStates` | 加入频道前缓存的临时用户状态超出限制。详见 [API 调用限制](/zh-CN/realtime-media/rtm/reference/usage-limits-and-errors/api-limits)。 | | `-13005` | `AgoraRtmErrorPresenceStateCountOverflow` | 临时用户状态键/值对数量超出限制。详见 [API 调用限制](/zh-CN/realtime-media/rtm/reference/usage-limits-and-errors/api-limits)。 | | `-13006` | `AgoraRtmErrorPresenceInvalidStateKey` | 无效状态键。 | | `-13007` | `AgoraRtmErrorPresenceInvalidStateValue` | 无效状态值。 | | `-13008` | `AgoraRtmErrorPresenceStateKeySizeOverflow` | 状态键长度溢出。 | | `-13009` | `AgoraRtmErrorPresenceStateValueSizeOverflow` | 状态值长度溢出 | | `-13010` | `AgoraRtmErrorPresenceStateDuplicateKey` | 重复的状态键。 | | `-13011` | `AgoraRtmErrorPresenceUserNotExist` | 该用户不存在。 | | `-13012` | `AgoraRtmErrorPresenceOperationTimeout` | Presence 操作超时。 | | `-13013` | `AgoraRtmErrorPresenceOperationFailed` | Presence 操作失败。 | | `-13014` | `AgoraRtmErrorPresenceInactive` | Presence 服务未开启或当前不可用。请检查声网控制台是否已开启 Presence 服务开关;未开启时,依赖该服务的 Presence API 和订阅选项不可用。 | | `-13015` | `AgoraRtmErrorPresencePendingRequestCancelled` | Presence 待处理请求已取消。调用 Presence 相关 API 后,如果请求完成前被取消,会返回该错误。 | | `-13016` | `AgoraRtmErrorPresencePendingRequestExceedLimitation` | Presence 待处理请求数量超过限制。请等待已有请求完成后重试。 | | `-14001` | `AgoraRtmErrorLockOperationFailed` | Lock 操作失败。 | | `-14002` | `AgoraRtmErrorLockOperationTimeout` | Lock 操作超时。 | | `-14003` | `AgoraRtmErrorLockOperationPerforming` | Lock 操作进行中。 | | `-14004` | `AgoraRtmErrorLockAlreadyExist` | Lock 已存在。 | | `-14005` | `AgoraRtmErrorLockInvalidName` | 无效 Lock 名。 | | `-14006` | `AgoraRtmErrorLockNotAcquired` | 未获取该 Lock。 | | `-14007` | `AgoraRtmErrorLockAcquireFailed` | 获取该 Lock 失败。 | | `-14008` | `AgoraRtmErrorLockNotExist` | 该 Lock 不存在。 | | `-14009` | `AgoraRtmErrorLockNotAvailable` | Lock 服务不可用。 | | `-15001` | `AgoraRtmErrorHistoryOperationFailed` | 历史消息的操作失败。 | | `-15002` | `AgoraRtmErrorHistoryInvalidTimestamp` | 历史消息的时间戳无效。 | | `-15003` | `AgoraRtmErrorHistoryOperationTimeout` | 历史消息的操作超时。 | | `-15004` | `AgoraRtmErrorHistoryOperationNotPermitted` | 没有权限进行历史消息的操作。 | | `-15005` | `AgoraRtmErrorHistoryNotAvailable` | 历史消息服务不可用。 | **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 仅支持如下频道类型,请填写正确的值: - `AgoraRtmChannelTypeMessage`: Message Channel - `AgoraRtmChannelTypeStream`: Stream Channel - `AgoraRtmChannelTypeUser`: 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** 登录操作已取消。可能原因如下: - 调用 `loginByToken` 方法后,如果你在收到调用结果之前再次调用该方法,则前一次的调用操作会被取消,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 是否正确。 - 检查远端用户是否登录系统并处于在线状态。 ## 联系我们 [#联系我们-1] 如果以上措施都为未能解决你的故障,或者你需要解决方案的支持,请将你的需求整理出来并通过邮箱发送到:rtm-support@agora.io。我们会在收到邮件的第一时间与你取得联系。