swift-sdk-demo 下载地址
https://github.com/leancloud/swift-sdk-demo1、先删除手机上的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)