PCSessionViewController.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // PCSessionViewController.m
  3. // WildFireChat
  4. //
  5. // Created by heavyrain lee on 2019/3/2.
  6. // Copyright © 2019 WildFireChat. All rights reserved.
  7. //
  8. #import "PCSessionViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "MBProgressHUD.h"
  11. #import "AppService.h"
  12. @interface PCSessionViewController ()
  13. @end
  14. @implementation PCSessionViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. [self.view setBackgroundColor:[UIColor whiteColor]];
  18. CGFloat width = [UIScreen mainScreen].bounds.size.width;
  19. CGFloat height = [UIScreen mainScreen].bounds.size.height;
  20. UIImageView *pcView = [[UIImageView alloc] initWithFrame:CGRectMake((width - 200)/2, 120, 200, 200)];
  21. pcView.image = [UIImage imageNamed:@"pc"];
  22. [self.view addSubview:pcView];
  23. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake((width - 200)/2, 320, 200, 16)];
  24. [label setText:@"电脑已登录"];
  25. [label setTextAlignment:NSTextAlignmentCenter];
  26. [self.view addSubview:label];
  27. UIButton *logoutBtn = [[UIButton alloc] initWithFrame:CGRectMake(100, height - 150, width - 200, 40)];
  28. [logoutBtn setBackgroundColor:[UIColor greenColor]];
  29. [logoutBtn setTitle:@"退出电脑登录" forState:UIControlStateNormal];
  30. logoutBtn.layer.masksToBounds = YES;
  31. logoutBtn.layer.cornerRadius = 5.f;
  32. [logoutBtn addTarget:self action:@selector(onLogoutBtn:) forControlEvents:UIControlEventTouchUpInside];
  33. [self.view addSubview:logoutBtn];
  34. }
  35. - (void)onLogoutBtn:(id)sender {
  36. __weak typeof(self)ws = self;
  37. [[WFCCIMService sharedWFCIMService] kickoffPCClient:self.pcClientInfo.clientId success:^{
  38. [ws sendLogoutDone:YES isLogin:YES];
  39. } error:^(int error_code) {
  40. [ws sendLogoutDone:NO isLogin:YES];
  41. }];
  42. }
  43. - (void)sendLogoutDone:(BOOL)result isLogin:(BOOL)isLogin {
  44. if (!result) {
  45. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  46. hud.mode = MBProgressHUDModeText;
  47. hud.label.text = @"网络错误";
  48. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  49. [hud hideAnimated:YES afterDelay:1.f];
  50. } else if(isLogin) {
  51. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  52. hud.mode = MBProgressHUDModeText;
  53. hud.label.text = @"成功";
  54. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  55. __weak typeof(self)ws = self;
  56. [hud setCompletionBlock:^{
  57. [ws.navigationController popViewControllerAnimated:YES];
  58. }];
  59. [hud hideAnimated:YES afterDelay:1.f];
  60. }
  61. }
  62. @end