问题基本描述

1.对于 iOS 和 Windows Phone 等平台,我们会在应用仍在前台时保持连接,当应用退到后台时,自动断开连接再激活平台原生的推送服务。这是LeanCloud文档的原话,可是ChatKitDemo里面,当应用退到后台时,并没有自动断开连接 的相关代码,只有[[LCChatKit sharedInstance] syncBadge];同步未读消息的badge。

2.而且首次运行,拿个未注册的新ClientId运行demo,会出现4111,被强制下线,点了强制登陆,强制登陆成功之后,再次运行(并没有点击退出当前账号),由于demo里面设置了autoLogin为YES,而且沙盒里有上次登录的clientId,所以会自动登录,但是随后又会出现是否强制登陆弹窗,所白了也就是一直会出现4111session conflict的问题,再次运行,再次出现4111,再次点了强制登陆,强制登陆成功之后,,再次出现4111,如此重复....为什么会出现这样的现象呢,运行的是最新ChatKitDemo,一行代码也没改。

1. ChatKit Version:0.7.17
2. App-ID: 原DemoAppID(dYRQ8YfHRiILshUnfFJu2eQM-gzGzoHsz)
3. Language:Objective-C
4. iOS System Version:iOS10
5. Prototype(是否是真机):NO
6. Issue Type:Q-A

1. How to repeat the problem.


拿个未注册的新ClientId运行demo,会出现4111,被强制下线,点了强制登陆,强制登陆成功之后,再次运行(并没有点击退出当前账号),由于demo里面设置了autoLogin为YES,而且沙盒里有上次登录的clientId,所以会自动登录,但是随后又会出现是否强制登陆弹窗,所白了也就是一直会出现4111session conflict的问题,再次运行,再次出现4111,再次点了强制登陆,强制登陆成功之后,,再次出现4111,,如此重复....为什么会出现这样的现象呢,运行的是最新ChatKitDemo,一行代码也没改。

2. Please help me in this way.


为什么会重复出现4111session conflict这样的现象呢,运行的是最新ChatKitDemo,一行代码也没改。

3. Here is a Demo.

master分支最新Chat-Kit代码

4. Here is my Debug log

objc[7111]: Class PLBuildVersion is implemented in both            /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibr aryServices(0x110c52910)and/Applications/Xcode.app/Contents/Developer/Platforms/   iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryS 
ervices (0x110a7c210). One of the two will be used. Which one is undefined.
    __                        ________                __
   / /   ___  ____ _____     / ____/ /___  __  ______/ /
  / /   / _ \/ __ `/ __ \   / /   / / __ \/ / / / __  / 
 / /___/  __/ /_/ / / / /  / /___/ / /_/ / /_/ / /_/ /  
/_____/\___/\__,_/_/ /_/   \____/_/\____/\__,_/\__,_/   
                                                    
appid: dYRQ8YfHRiILshUnfFJu2eQM-gzGzoHsz
device_model: x86_64
carrier: 
access: 
app_version: 0.4.9
sdk_version: v3.4.3
os: iOS
package_name: com.redpacket.chatkit
display_name: ChatKit-OC
language: zh-Hans-US
sv: 4
device_id: 15D2AE96-96F1-487B-B1E6-5D3A9FD7EDBD
is_jailbroken: 0
resolution: 750 x 1334
os_version: 10.0
timezone: 8
----------------------------------------------------------
2016-10-12 16:13:57.522 ChatKit-OC[7111:197652] [DEBUG] -[AVPaasClient   

performRequest:success:failure:] [Line 654] 

 ------ BEGIN LeanCloud REST Request -------
  path: /1/route
 curl: curl -i -k -X GET --compressed -H 'Accept: application/json' -H 'Content-Type:                      
 application/json; charset=utf-8' -H 'X-LC-Sign:      
 046a5b3ff3cf5b3fa651e2f045e520be,1476260037522' -H 'User-Agent: AVOS Cloud iOS-v3.4.3      
 SDK' -H 'Accept-Language: zh-Hans-US;q=1, en;q=0.9' -H 'X-LC-Id:  
 dYRQ8YfHRiILshUnfFJu2eQM-  
 gzGzoHsz' -H 'X-LC-Prod: 1' --data-urlencode 'appId=dYRQ8YfHRiILshUnfFJu2eQM-gzGzoHsz'   
"https://app-router.leancloud.cn/1/route"
------ END --------------------------------

2016-10-12 16:13:57.525 ChatKit-OC[7111:197652] [DEBUG] -[AVPaasClient    
performRequest:success:failure:] [Line 654] 

------ BEGIN LeanCloud REST Request -------
path: /1.1/statistics/apps/dYRQ8YfHRiILshUnfFJu2eQM-gzGzoHsz/sendPolicy
curl: curl -i -k -X GET --compressed -H 'Accept: application/json' -H 'Content-Type:   
application/json; charset=utf-8' -H 'X-LC-Sign: 
cc476dc5702a54464e79f5254fdeae43,1476260037525' -H 'User-Agent: AVOS Cloud iOS-v3.4.3 
SDK' -H 'Accept-Language: zh-Hans-US;q=1, en;q=0.9' -H 'X-LC-Id:   
dYRQ8YfHRiILshUnfFJu2eQM-
gzGzoHsz' -H 'X-LC-Prod: 1'   
"https://api.leancloud.cn/1.1/statistics/apps/dYRQ8YfHRiILshUnfFJu2eQM-gzGzoHsz/sendPolicy"
------ END --------------------------------

2016-10-12 16:13:57.527 ChatKit-OC[7111:197652] -[LCCKConversationService   
setupSucceedMessageDatabaseWithPath:] [Line 211] database queue should not be nil !!!!
2016-10-12 16:13:57.536 ChatKit-OC[7111:197751] [DEBUG] __59-[AVPaasClient     
performRequest:saveResult:block:retryTimes:]_block_invoke [Line 577] 

------ BEGIN LeanCloud REST Response ------
 path: /1/route
 cost: 0.006s
 response: {
     "api_server" = "api.leancloud.cn";
     "push_router_server" = "router-g0-push.leancloud.cn";
     ttl = 3600;
 }
 ------ END --------------------------------

2016-10-12 16:13:57.544 ChatKit-OC[7111:197747] [INFO] __60-[AVIMWebSocketWrapper    
openWebSocketConnectionWithCallback:]_block_invoke [Line 386] Open websocket connection.
2016-10-12 16:13:57.546 ChatKit-OC[7111:197747] [DEBUG] -[AVPaasClient  
performRequest:success:failure:] [Line 654] 

------ BEGIN LeanCloud REST Request -------
path: /v1/route
curl: curl -i -k -X GET --compressed -H 'Accept: application/json' -H 'Content-Type:   
application/json; charset=utf-8' -H 'X-LC-Sign:       
b508031f01fa5b5a5178479b225cfe46,1476260037545' -H 'User-Agent: AVOS Cloud iOS-v3.4.3     
SDK' -H 'Accept-Language: zh-Hans-US;q=1, en;q=0.9' -H 'X-LC-Id:  
dYRQ8YfHRiILshUnfFJu2eQM-
gzGzoHsz' -H 'X-LC-Prod: 1' --data-urlencode 'appId=dYRQ8YfHRiILshUnfFJu2eQM-gzGzoHsz' --  
data-urlencode 'ip=true' --data-urlencode 'secure=1' "https://router-g0-  
push.leancloud.cn/v1/route"
------ END --------------------------------

2016-10-12 16:13:57.728 ChatKit-OC[7111:197652] [INFO] __26-[AVPaasClient    

clientImpl]_block_invoke [Line 257] network status change :2
2016-10-12 16:13:57.734 ChatKit-OC[7111:197652] Autocomplete table view will be added to the    
view hierarchy
2016-10-12 16:13:57.954 ChatKit-OC[7111:197769] [DEBUG] __59-[AVPaasClient   
performRequest:saveResult:block:retryTimes:]_block_invoke [Line 577] 

------ BEGIN LeanCloud REST Response ------
path: /1.1/statistics/apps/dYRQ8YfHRiILshUnfFJu2eQM-gzGzoHsz/sendPolicy
cost: 0.429s
response: {
    enable = 1;
    parameters =     {
    };
    policy = 7;
}
------ END --------------------------------

2016-10-12 16:14:02.128 ChatKit-OC[7111:197769] [INFO] -[AVIMWebSocketWrapper    
internalOpenWebSocketConnection:] [Line 564] Open websocket with url:   
wss://rtm57.leancloud.cn:6799/
2016-10-12 16:14:02.131 ChatKit-OC[7111:197769] [DEBUG] __59-[AVPaasClient   
performRequest:saveResult:block:retryTimes:]_block_invoke [Line 577] 

------ BEGIN LeanCloud REST Response ------
path: /v1/route
cost: 4.582s
response: {
    groupId = g0;
    secondary = "wss://rtm57.leancloud.cn:6799/";
    server = "wss://rtm57.leancloud.cn:6799/";
    ttl = 3600;
}
------ END --------------------------------

2016-10-12 16:14:02.332 ChatKit-OC[7111:197652] [INFO] -[AVIMWebSocketWrapper    
webSocketDidOpen:] [Line 745] Websocket connection opened.
2016-10-12 16:14:02.333 ChatKit-OC[7111:197747] [INFO] -[AVIMWebSocketWrapper   
sendCommand:] [Line 689] 

------ BEGIN LeanCloud IM Out Command ------
cmd: Session
type: AVIMSessionCommand
content: <AVIMGenericCommand 0x6000001d6530>: {
      cmd: session
      op: open
      appId: "dYRQ8YfHRiILshUnfFJu2eQM-gzGzoHsz"
      peerId: "nnnnnnnnmmmmsssss"
      sessionMessage {
      ua: "ios/v3.4.3"
      r: true
      tag: "nnnnnnnnmmmmsssss"
      deviceToken: "acc90989-73d1-4401-9403-3e40f8a04bbf"
    }
}
------ END ---------------------------------

2016-10-12 16:14:02.385 ChatKit-OC[7111:197652] [INFO] -[AVIMWebSocketWrapper 
webSocket:didReceiveMessage:] [Line 761] 

------ BEGIN LeanCloud IM In Command ------
content: <AVIMGenericCommand 0x6080001d68f0>: {
    cmd: session
    op: closed
    appId: "dYRQ8YfHRiILshUnfFJu2eQM-gzGzoHsz"
    peerId: "nnnnnnnnmmmmsssss"
    i: 1
    sessionMessage {
      code: 4111
      reason: "SESSION_CONFLICT"
    }
}
------ END --------------------------------

2016-10-12 16:14:02.397 ChatKit-OC[7111:197652] Error Domain=AVOSCloudIMErrorDomain    
Code=4111 "SESSION_CONFLICT" UserInfo={code=4111,    
NSLocalizedFailureReason=SESSION_CONFLICT, reason=SESSION_CONFLICT}
2016-10-12 16:14:02.425 ChatKit-OC[7111:197652] [INFO] -[AVIMWebSocketWrapper   
closeWebSocketConnectionRetry:] [Line 607] Close websocket connection.
2016-10-12 16:14:02.496 ChatKit-OC[7111:197652] [DEBUG] -[AVIMWebSocketWrapper   
webSocket:didCloseWithCode:reason:wasClean:] [Line 817] Websocket closed with code:1001,   
reason:Stream end encountered.

你好,这个问题我们已经收到,正在查看问题,有进展将进一步回复。

这个 问题实在 抱歉,我刚发现了问题了,后来 想编辑帖子的问题描述,发现一直编辑失败。我最终发现原因 是因为更新Xcode之后 运行iOS10的模拟器导致会一直弹出强制登录,而运行iOS9.3的模拟器却不会出现这样的状况,估计是个iOS10模拟器的bug,在真机上运行 的确不会 再次出现了。这个是我的疏忽,没测试周全。
听您那么说,确实是这样, 得用DeviceToken当作tag来区分是否为唯一设备,只是有个疑惑,demo代码里面单点登录不是通过获取当前用户的clientId作为tag绑定的吗,怎么不是根据DeviceToken来做tag的了,这样做不会有问题?

[[LCCKConversationService sharedInstance] setupDatabaseWithUserId:_clientId];
//判断是否是第一次使用该appId
[[LCChatKit sharedInstance] lcck_isFirstLaunchToEvent:[LCChatKit sharedInstance].appId
                                           evenUpdate:YES
                                          firstLaunch:^BOOL(){
                                              return [[LCChatKit sharedInstance] removeAllCachedRecentConversations];
                                          }];
//    [[CDFailedMessageStore store] setupStoreWithDatabasePath:dbPath];
NSString *tag;
if (!self.disableSingleSignOn) {
    tag = clientId;
}
_client = [[AVIMClient alloc] initWithClientId:clientId tag:tag];
_client.delegate = self;
/* 实现了generateSignatureBlock,将对 im 的 open , start(create conv), kick, invite 操作签名,更安全.
 可以从你的服务器获得签名,也可以部署云代码获取 https://leancloud.cn/docs/leanengine_overview.html .
 */

代码里面时使用clientId做tag的,没看到用deviceToken来做tag的...