Hale Cai
2018-08-10 42c80d0b43ff8736edb5be4bbfcbc7a99fc8a119
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
//  SetTagsViewController.m
//  PushSDK
//
//  Created by ys on 16/05/2017.
//  Copyright © 2017 hxhg. All rights reserved.
//
 
#import "SetTagsViewController.h"
#import "JPUSHService.h"
@interface SetTagsViewController ()
 
@property (weak, nonatomic) IBOutlet UITextField *tagsTextField;
@property (weak, nonatomic) IBOutlet UITextField *aliasTextField;
@property (weak, nonatomic) IBOutlet UITextView *holderTextView;
 
@end
 
@implementation SetTagsViewController
 
static NSInteger seq = 0;
 
- (void)viewDidLoad {
    [super viewDidLoad];
    self.holderTextView.layer.borderColor = [UIColor lightGrayColor].CGColor;
}
 
- (IBAction)addTags:(id)sender {
    [JPUSHService addTags:[self tags] completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
      [self inputResponseCode:iResCode content:[NSString stringWithFormat:@"%@", iTags.allObjects] andSeq:seq];
    } seq:[self seq]];
}
- (IBAction)setTags:(id)sender {
    [JPUSHService setTags:[self tags] completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
      [self inputResponseCode:iResCode content:[NSString stringWithFormat:@"%@", iTags.allObjects] andSeq:seq];
    } seq:[self seq]];
}
- (IBAction)getAllTags:(id)sender {
    [JPUSHService getAllTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
      [self inputResponseCode:iResCode content:[NSString stringWithFormat:@"%@", iTags.allObjects] andSeq:seq];
    } seq:[self seq]];
}
- (IBAction)deleteTags:(id)sender {
    [JPUSHService deleteTags:[self tags] completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
      [self inputResponseCode:iResCode content:[NSString stringWithFormat:@"%@", iTags.allObjects] andSeq:seq];
    } seq:[self seq]];
}
- (IBAction)cleanTags:(id)sender {
    [JPUSHService cleanTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
      [self inputResponseCode:iResCode content:[NSString stringWithFormat:@"%@", iTags.allObjects] andSeq:seq];
    } seq:[self seq]];
}
- (IBAction)vaildTag:(id)sender {
  [JPUSHService validTag:[[self tags] anyObject] completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq, BOOL isBind) {
    [self inputResponseCode:iResCode content:[NSString stringWithFormat:@"%@ isBind:%d", iTags.allObjects, isBind] andSeq:seq];
  } seq:[self seq]];
}
 
- (IBAction)setAlias:(id)sender {
    [JPUSHService setAlias:[self alias] completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
      [self inputResponseCode:iResCode content:iAlias andSeq:seq];
    } seq:[self seq]];
}
- (IBAction)deleteAlias:(id)sender {
  [JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
    [self inputResponseCode:iResCode content:iAlias andSeq:seq];
  } seq:[self seq]];
}
- (IBAction)getAlias:(id)sender {
  [JPUSHService getAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
    [self inputResponseCode:iResCode content:iAlias andSeq:seq];
  } seq:[self seq]];
}
- (IBAction)resetTextField:(id)sender {
  self.tagsTextField.text = nil;
  self.aliasTextField.text = nil;
}
- (IBAction)resetTextView:(id)sender {
  self.holderTextView.text = nil;
}
 
- (NSInteger)seq {
  return ++ seq;
}
 
- (NSSet<NSString *> *)tags {
  NSArray * tagsList = [self.tagsTextField.text componentsSeparatedByString:@","];
  if (self.tagsTextField.text.length > 0 && !tagsList.count) {
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"没有输入tags,请使用逗号作为tags分隔符" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
  }
  NSMutableSet * tags = [[NSMutableSet alloc] init];
  [tags addObjectsFromArray:tagsList];
  return tags;
}
 
- (NSString *)alias {
  return self.aliasTextField.text;
}
 
- (void)inputResponseCode:(NSInteger)code content:(NSString *)content andSeq:(NSInteger)seq{
  self.holderTextView.text = [self.holderTextView.text stringByAppendingFormat:@"\n\n code:%ld content:%@ seq:%ld", code, content, seq];
}
 
- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [JPUSHService startLogPageView:NSStringFromClass(self.class)];
}
 
- (void)viewWillDisappear:(BOOL)animated {
  [super viewWillDisappear:animated];
  [JPUSHService stopLogPageView:NSStringFromClass(self.class)];
}
 
- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  [self.tagsTextField resignFirstResponder];
  [self.aliasTextField resignFirstResponder];
}
 
@end