AppViewModel.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //
  2. // AppViewModel.m
  3. // BuguLive
  4. //
  5. // Created by xfg on 16/10/25.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "AppViewModel.h"
  9. @implementation AppViewModel
  10. #pragma mark 客户在线情况监测
  11. /**
  12. 提交在线、离线接口
  13. @param status Login:在线 Logout:离线
  14. */
  15. + (void)userStateChange:(NSString *)status
  16. {
  17. // 如果没有登录,就不需要后续操作
  18. if (![IMAPlatform isAutoLogin])
  19. {
  20. return;
  21. }
  22. if (![BGUtils isBlankString:[GlobalVariables sharedInstance].appModel.on_line_group_id])
  23. {
  24. if ([status isEqualToString:@"Login"])
  25. {
  26. [[V2TIMManager sharedInstance] joinGroup:[GlobalVariables sharedInstance].appModel.on_line_group_id msg:nil succ:^{
  27. } fail:^(int code, NSString *desc) {
  28. }];
  29. /*[[TIMGroupManager sharedInstance] joinGroup:[GlobalVariables sharedInstance].appModel.on_line_group_id msg:nil succ:^{
  30. NSLog(ASLocalizedString(@"加入在线用户大群成功"));
  31. } fail:^(int code, NSString *msg) {
  32. NSLog(ASLocalizedString(@"加入在线用户大群失败,错误码:%d,错误原因:%@"),code,msg);
  33. }];*/
  34. }
  35. else if ([status isEqualToString:@"Logout"])
  36. {
  37. if (![BGUtils isBlankString:[GlobalVariables sharedInstance].appModel.on_line_group_id]) {
  38. // [[TIMGroupManager sharedInstance] quitGroup:[GlobalVariables sharedInstance].appModel.on_line_group_id succ:^{
  39. // NSLog(ASLocalizedString(@"退出在线用户大群成功"));
  40. // } fail:^(int code, NSString *msg) {
  41. // NSLog(ASLocalizedString(@"退出在线用户大群失败,错误码:%d,错误原因:%@"),code,msg);
  42. // }];
  43. [[V2TIMManager sharedInstance] quitGroup:[GlobalVariables sharedInstance].appModel.on_line_group_id succ:^{
  44. } fail:^(int code, NSString *desc) {
  45. }];
  46. }
  47. }
  48. }
  49. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  50. [mDict setObject:@"user" forKey:@"ctl"];
  51. [mDict setObject:@"state_change" forKey:@"act"];
  52. [mDict setObject:status forKey:@"action"];
  53. [[NetHttpsManager manager] POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  54. } FailureBlock:^(NSError *error) {
  55. }];
  56. }
  57. #pragma mark 上传当前用户设备号
  58. + (void)updateApnsCode
  59. {
  60. // 如果没有登录,就不需要后续操作
  61. if (![IMAPlatform isAutoLogin])
  62. {
  63. return;
  64. }
  65. GlobalVariables *BuguLive = [GlobalVariables sharedInstance];
  66. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  67. [mDict setObject:@"user" forKey:@"ctl"];
  68. [mDict setObject:@"apns" forKey:@"act"];
  69. if (![BGUtils isBlankString:BuguLive.deviceToken])
  70. {
  71. [mDict setObject:BuguLive.deviceToken forKey:@"apns_code"];
  72. [[NetHttpsManager manager] POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  73. NSLog(@"===:%@",responseJson);
  74. } FailureBlock:^(NSError *error) {
  75. }];
  76. }
  77. }
  78. + (void)updateApnsVoipCode {
  79. // 如果没有登录,就不需要后续操作
  80. if (![IMAPlatform isAutoLogin])
  81. {
  82. return;
  83. }
  84. GlobalVariables *BuguLive = [GlobalVariables sharedInstance];
  85. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  86. [mDict setObject:@"user" forKey:@"ctl"];
  87. [mDict setObject:@"apns_voip" forKey:@"act"];
  88. if (![BGUtils isBlankString:BuguLive.deviceToken])
  89. {
  90. [mDict setObject:BuguLive.voip_deviceToken forKey:@"apns_voip_code"];
  91. [[NetHttpsManager manager] POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  92. NSLog(@"===:%@",responseJson);
  93. } FailureBlock:^(NSError *error) {
  94. }];
  95. }
  96. }
  97. #pragma mark 重新加载初始化接口
  98. + (void)loadInit
  99. {
  100. GlobalVariables *BuguLive = [GlobalVariables sharedInstance];
  101. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  102. [parmDict setObject:@"app" forKey:@"ctl"];
  103. [parmDict setObject:@"init" forKey:@"act"];
  104. NSString *postUrl;
  105. #if kSupportH5Shopping
  106. postUrl = H5InitUrlStr;
  107. #else
  108. postUrl = BuguLive.currentDoMianUrlStr;
  109. #endif
  110. [[NetHttpsManager manager] POSTWithUrl:postUrl paramDict:parmDict SuccessBlock:^(NSDictionary *responseJson)
  111. {
  112. BuguLive.appModel = [AppModel mj_objectWithKeyValues:responseJson];
  113. if (BuguLive.listMsgMArray)
  114. {
  115. [BuguLive.listMsgMArray removeAllObjects];
  116. }
  117. NSArray *listmsg = [responseJson objectForKey:@"listmsg"];
  118. if (listmsg && [listmsg isKindOfClass:[NSArray class]])
  119. {
  120. for (NSDictionary *tmpDic in listmsg)
  121. {
  122. CustomMessageModel *customMessageModel = [CustomMessageModel mj_objectWithKeyValues:tmpDic];
  123. [customMessageModel prepareForRender];
  124. [BuguLive.listMsgMArray addObject:customMessageModel];
  125. }
  126. }
  127. } FailureBlock:^(NSError *error) {
  128. }];
  129. }
  130. @end