DeviceInfoViewController.m 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // DeviceInfoViewController.m
  3. // WildFireChat
  4. //
  5. // Created by Tom Lee on 2020/5/1.
  6. // Copyright © 2020 WildFireChat. All rights reserved.
  7. //
  8. #import "DeviceInfoViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "MBProgressHUD.h"
  11. @interface DeviceInfoViewController ()
  12. @property(nonatomic, strong)UILabel *nameLabel;
  13. @property(nonatomic, strong)UILabel *idLabel;
  14. @property(nonatomic, strong)UILabel *tokenLabel;
  15. @property(nonatomic, strong)UILabel *ownerLabel;
  16. @end
  17. @implementation DeviceInfoViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.view.backgroundColor = [UIColor whiteColor];
  21. CGFloat width = self.view.bounds.size.width;
  22. self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 120, width - 32, 20)];
  23. self.nameLabel.text = [NSString stringWithFormat:@"设备名称:%@", self.device.name];
  24. [self.view addSubview:self.nameLabel];
  25. self.idLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 148, width - 32, 20)];
  26. self.idLabel.text = [NSString stringWithFormat:@"设备ID:%@", self.device.deviceId];
  27. [self.view addSubview:self.idLabel];
  28. self.tokenLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 176, width - 32, 20)];
  29. self.tokenLabel.text = [NSString stringWithFormat:@"设备令牌:%@", self.device.token];
  30. [self.view addSubview:self.tokenLabel];
  31. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"发送给我" style:UIBarButtonItemStyleDone target:self action:@selector(onRightBtn:)];
  32. }
  33. - (void)onRightBtn:(id)sender {
  34. __weak typeof(self) ws = self;
  35. __block MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  36. hud.label.text = @"发送中...";
  37. [hud showAnimated:YES];
  38. WFCCConversation *conv = [WFCCConversation conversationWithType:Single_Type target:[WFCCNetworkService sharedInstance].userId line:0];
  39. WFCCTextMessageContent *textContent = [WFCCTextMessageContent contentWith:[NSString stringWithFormat:@"DeviceName:%@, \nDeviceId:%@, \nToken:%@", self.device.name, self.device.deviceId, self.device.token]];
  40. [[WFCCIMService sharedWFCIMService] send:conv content:textContent success:^(long long messageUid, long long timestamp) {
  41. [hud hideAnimated:NO];
  42. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  43. hud.mode = MBProgressHUDModeText;
  44. hud.label.text = @"发送成功";
  45. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  46. [hud hideAnimated:YES afterDelay:1.f];
  47. } error:^(int error_code) {
  48. [hud hideAnimated:NO];
  49. hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  50. hud.mode = MBProgressHUDModeText;
  51. hud.label.text = @"发送失败";
  52. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  53. [hud hideAnimated:YES afterDelay:1.f];
  54. }];
  55. }
  56. /*
  57. #pragma mark - Navigation
  58. // In a storyboard-based application, you will often want to do a little preparation before navigation
  59. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  60. // Get the new view controller using [segue destinationViewController].
  61. // Pass the selected object to the new view controller.
  62. }
  63. */
  64. @end