WFPttCreateChannelViewController.m 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // WFPttCreateChannelViewController.m
  3. // PttUIKit
  4. //
  5. // Created by Hao Jia on 2021/10/14.
  6. //
  7. #ifdef WFC_PTT
  8. #import "WFPttCreateChannelViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import <PttClient/WFPttClient.h>
  11. @interface WFPttCreateChannelViewController () <UITextFieldDelegate>
  12. @property(nonatomic, strong)UITextField *titleTextField;
  13. @end
  14. @implementation WFPttCreateChannelViewController
  15. #define Label_Width 80
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.view.backgroundColor = [UIColor whiteColor];
  19. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(16, kStatusBarAndNavigationBarHeight + 8, Label_Width, 24)];
  20. label.text = @"频道名称";
  21. [self.view addSubview:label];
  22. self.view.backgroundColor = [UIColor whiteColor];
  23. self.titleTextField = [[UITextField alloc] initWithFrame:CGRectMake(16 + Label_Width, kStatusBarAndNavigationBarHeight + 8, self.view.bounds.size.width - 16 - Label_Width - 16, 24)];
  24. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[WFCCNetworkService sharedInstance].userId refresh:NO];
  25. self.titleTextField.text = [NSString stringWithFormat:@"%@的频道", userInfo.displayName];
  26. self.titleTextField.borderStyle = UITextBorderStyleBezel;
  27. self.titleTextField.returnKeyType = UIReturnKeyDone;
  28. self.titleTextField.delegate = self;
  29. [self.view addSubview:self.titleTextField];
  30. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(dismiss:)];
  31. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"创建" style:UIBarButtonItemStylePlain target:self action:@selector(onStart:)];
  32. }
  33. - (void)dismiss:(id)sender {
  34. if (self.navigationController.presentingViewController) {
  35. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  36. }else{
  37. [self.navigationController popViewControllerAnimated:YES];
  38. }
  39. }
  40. - (void)onStart:(id)sender {
  41. self.navigationItem.rightBarButtonItem.enabled = NO;
  42. __weak typeof(self)ws = self;
  43. [[WFPttClient sharedClient] createChannel:nil channelName:self.titleTextField.text channelPortrait:nil maxSpeakerNumber:0 saveVoiceMessage:YES maxSpeakerTime:0 success:^(NSString *cid) {
  44. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  45. [ws dismiss:nil];
  46. });
  47. } error:^(int errorCode) {
  48. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:@"糟糕,出错了" preferredStyle:UIAlertControllerStyleAlert];
  49. __weak typeof(self)ws = self;
  50. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"等会再试试吧!" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  51. [ws dismiss:nil];
  52. }];
  53. [actionSheet addAction:actionCancel];
  54. [self presentViewController:actionSheet animated:YES completion:nil];
  55. }];
  56. }
  57. #pragma mark - UITextFieldDelegate
  58. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  59. [textField resignFirstResponder];
  60. return YES;
  61. }
  62. @end
  63. #endif //WFC_PTT