IMAPlatform+Login.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // IMAPlatform+Login.m
  3. // TIMChat
  4. //
  5. // Created by AlexiChen on 16/2/26.
  6. // Copyright © 2016年 AlexiChen. All rights reserved.
  7. //
  8. #import "IMAPlatform+Login.h"
  9. #import "BogoNetworkKit.h"
  10. #import <ImSDK_Plus/ImSDK_Plus.h>
  11. @implementation IMAPlatform (Login)
  12. //互踢下线错误码
  13. #define kEachKickErrorCode 6208
  14. - (void)loginTIMSDK:(TIMLoginParam *)param succ:(TIMLoginSucc)succ fail:(TIMFail)fail
  15. {
  16. if (!param)
  17. {
  18. return;
  19. }
  20. __weak IMAPlatform *ws = self;
  21. [[V2TIMManager sharedInstance] login:param.identifier userSig:param.userSig succ:^{
  22. DebugLog(@"登录成功:%@ tinyid:%llu sig:%@", param.identifier, [[IMSdkInt sharedInstance] getTinyId], param.userSig);
  23. [IMAPlatform setAutoLogin:YES];
  24. [BogoNetwork shareInstance].uid = param.identifier;
  25. if (succ)
  26. {
  27. succ();
  28. }
  29. } fail:^(int code, NSString *desc) {
  30. DebugLog(@"TIMLogin Failed: code=%d err=%@", code, desc);
  31. if (code == kEachKickErrorCode)
  32. {
  33. // 互踢重联
  34. // 重新再登录一次
  35. [ws offlineKicked:param succ:succ fail:fail];
  36. }
  37. else
  38. {
  39. if (fail)
  40. {
  41. fail(code, desc);
  42. }
  43. }
  44. }];
  45. /*[[TIMManager sharedInstance] login:param succ:^{
  46. DebugLog(@"登录成功:%@ tinyid:%llu sig:%@", param.identifier, [[IMSdkInt sharedInstance] getTinyId], param.userSig);
  47. [IMAPlatform setAutoLogin:YES];
  48. [BogoNetwork shareInstance].uid = param.identifier;
  49. if (succ)
  50. {
  51. succ();
  52. }
  53. } fail:^(int code, NSString *msg) {
  54. DebugLog(@"TIMLogin Failed: code=%d err=%@", code, msg);
  55. if (code == kEachKickErrorCode)
  56. {
  57. // 互踢重联
  58. // 重新再登录一次
  59. [ws offlineKicked:param succ:succ fail:fail];
  60. }
  61. else
  62. {
  63. if (fail)
  64. {
  65. fail(code, msg);
  66. }
  67. }
  68. }];*/
  69. }
  70. //离线被踢
  71. //用户离线时,在其它终端登录过,再次在本设备登录时,会提示被踢下线,需要重新登录
  72. - (void)offlineKicked:(TIMLoginParam *)param succ:(TIMLoginSucc)succ fail:(TIMFail)fail
  73. {
  74. // UIAlertView *alert = [UIAlertView bk_showAlertViewWithTitle:@"下线通知" message:@"您的帐号于另一台手机上登录。" cancelButtonTitle:@"退出" otherButtonTitles:@[@"重新登录"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
  75. // if (buttonIndex == 0)
  76. // {
  77. // // 退出
  78. // [self logout:^{
  79. // [[AppDelegate sharedAppDelegate] enterLoginUI];
  80. // } fail:^(int code, NSString *msg) {
  81. // [[AppDelegate sharedAppDelegate] enterLoginUI];
  82. // }];
  83. // }
  84. // else
  85. // {
  86. [self offlineLogin];
  87. // 重新登录
  88. [self loginTIMSDK:param succ:succ fail:fail];
  89. // }
  90. // }];
  91. // [alert show];
  92. }
  93. - (void)configOnEnterMainUIWith:(TIMLoginParam *)param
  94. {
  95. // 配置, 获取个人名片
  96. [self configHost:param];
  97. // TODO:用户可结合自身逻辑,看是否处理退历器直播间消息
  98. [self asyncExitHistoryAVChatRoom];
  99. }
  100. @end