swift-sdk-demo 下载地址 https://github.com/leancloud/swift-sdk-demo1
1、先删除手机上的demo程序,重新安装demo,2、登录页全选OFF,Cliient ID选James,弹窗选取消通知,取消位置 3、点击对话列表中某一个对话,进入消息页面,然后返回到对话列表,按home键(iphone 7plus),程序退到后台。4、然后再进入对话列表,按顺序点击未点击过的对话,进入消息页面,然后再返回对话列表,然后按home键进入后台,这样重复。“偶尔”会发现,如果再点击已经点击过的对话列表,会发生崩溃:Thread 1: Assertion failed。好像如果程序运行过程中不按home键来回切换对话就一直没事。但按了home键,再进入某一对话的消息页面“偶尔”就会崩溃。
发生问题的方法(见图)是:
public func queryMessage(
start: MessageQueryEndpoint? = nil,
end: MessageQueryEndpoint? = nil,
direction: MessageQueryDirection? = nil,
limit: Int = 20,
type: IMMessageCategorizing.MessageType? = nil,
policy: MessageQueryPolicy = .default,
completion: @escaping (LCGenericResult<[IMMessage]>) -> Void)
throws
{
guard IMConversation.limitRangeOfMessageQuery.contains(limit) else {
throw LCError(
code: .inconsistency,
reason: "limit should in range (IMConversation.limitRangeOfMessageQuery)"
)
}
var underlyingPolicy: MessageQueryPolicy = policy
if [ConvType.transient, ConvType.temporary].contains(self.convType) || type != nil {
underlyingPolicy = .onlyNetwork
} else {
if underlyingPolicy == .default {
if let client = self.client, client.options.contains(.usingLocalStorage) {
underlyingPolicy = .cacheThenNetwork
} else {
underlyingPolicy = .onlyNetwork
}
}
}
switch underlyingPolicy {
case .default:
fatalError("never happen")
case .onlyNetwork:
self.queryMessageOnlyNetwork(
start: start,
end: end,
direction: direction,
limit: limit,
type: type)
{ (client, result) in
assert(client.specificAssertion)
client.eventQueue.async {
completion(result)
}
}
case .onlyCache:
guard let localStorage = self.client?.localStorage else {
throw LCError.clientLocalStorageNotFound
}
self.queryMessageOnlyCache(
localStorage: localStorage,
start: start,
end: end,
direction: direction,
limit: limit)
{ (client, result, _) in
assert(client.specificAssertion)
client.eventQueue.async {
completion(result)
}
}
case .cacheThenNetwork:
guard let localStorage = self.client?.localStorage else {
throw LCError.clientLocalStorageNotFound
}
self.queryMessageOnlyCache(
localStorage: localStorage,
start: start,
end: end,
direction: direction,
limit: limit)
{ (client, result, hasBreakpoint) in
var shouldUseNetwork: Bool = (hasBreakpoint || result.isFailure)
if !shouldUseNetwork, let value = result.value {
shouldUseNetwork = (value.count != limit)
}
if shouldUseNetwork {
self.queryMessageOnlyNetwork(
start: start,
end: end,
direction: direction,
limit: limit,
type: nil)
{ (client, result) in
client.eventQueue.async {
completion(result)
}
}
} else {
client.eventQueue.async {
completion(result)
}
}
}
}
}

发生在assert(client.specificAssertion) 这一行。
请帮忙看看问题出在哪里,怎么解决。

另外,输出显示为:
[💛][verbose][LeanCloud][2019-09-17 10:00:13.421][RTMConnection.swift][#438][init(application:lcimProtocol:)]: Application did enter background
[💛][verbose][LeanCloud][2019-09-17 10:00:13.758][RTMConnection.swift][#446][init(application:lcimProtocol:)]: Application will enter foreground
[💛][verbose][LeanCloud][2019-09-17 10:00:13.759][RTMConnection.swift][#657][connectingWorkItem()]: connecting URL<"wss://cn-n1-cell2.leancloud.cn/"> with protocol<"lc.protobuf2.3">
Assertion failed: file /Users/glk/Desktop/swift-sdk-demo-master/swift-sdk-demo/Pods/LeanCloud/Sources/IM/IMConversation.swift, line 1185
2019-09-17 10:00:14.587755+0800 Chat[251:5515] Assertion failed: file /Users/glk/Desktop/swift-sdk-demo-master/swift-sdk-demo/Pods/LeanCloud/Sources/IM/IMConversation.swift, line 1185
(lldb)

已经确认问题原因,该问题只会在 Debug 模式中出现,会在下个版本修复该问题。

感谢您的反馈。

非常感谢这么晚还在坚持工作解答问题,谢谢

16.5.1 已经发布,修复该问题。

从这个地址下载swift-sdk-demo: https://github.com/leancloud/swift-sdk-demo
【不是从 https://github.com/leancloud/swift-sdk 下载】
第一个地址的demo最新的版本目前显示是1个月前更新的版本,进入podfile,修改pod 'LeanCloud', '~> 16.5.1'
pod update后运行demo 【运行 https://github.com/leancloud/swift-sdk-demo 这个demo】,进入对话列表,打开对话进入消息页面,然后返回对话列表,然后按home键。然后重复:进入对话列表,按顺序点击没打开过的对话,打开消息页面,然后返回对话列表,然后按home键。。。然后点击某一个曾经点击过的对话。没有崩溃现象了,但“偶尔”会出弹出LCError对话框,这个其实不影响使用,点ok后也能正常显示消息页面了,就是偶尔会出现这个错误提示(使用过程中如果不按home键,demo运行是很正常的,按home键才会很偶然的情况下出现LCError的提示,不会经常出现)

iOS 应用进入后台后,SDK 会主动断开连接;应用进入前台后,SDK 会自动恢复连接。

目前的 Demo 没有在 UI 上展示网络状态,后续我们会对 Demo 进行改进。