/
SCTwitterViewController.m
193 lines (155 loc) · 4.75 KB
/
SCTwitterViewController.m
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//
// SCTwitterViewController.m
// SCTwitter
//
// Created by Lucas Correa on 29/02/12.
// Copyright (c) 2012 Siriuscode Solutions. All rights reserved.
//
#import "SCTwitterViewController.h"
#import "SCTwitter.h"
@implementation SCTwitterViewController
@synthesize messageText;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
//Loading
loadingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.8];
UIActivityIndicatorView *aiView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[loadingView addSubview:aiView];
[aiView startAnimating];
aiView.center = CGPointMake(160, 240);
[aiView release];
[self.view addSubview:loadingView];
loadingView.hidden = YES;
}
- (void)viewDidUnload
{
[self setMessageText:nil];
[self setBackground:nil];
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (UIInterfaceOrientationPortrait == interfaceOrientation);
}
#pragma mark - Button Action
- (IBAction)loginButtonAction:(id)sender
{
loadingView.hidden = NO;
[SCTwitter loginViewControler:self callback:^(BOOL success){
loadingView.hidden = YES;
if (success) {
NSLog(@"Login is Success - %i", success);
Alert(@"Alert", @"Success");
}
}];
}
- (IBAction)logoutButtonAction:(id)sender
{
loadingView.hidden = NO;
[SCTwitter logoutCallback:^(BOOL success) {
loadingView.hidden = YES;
NSLog(@"Logout is Success - %i", success);
Alert(@"Alert", @"Logout successfully");
}];
}
- (IBAction)postBackgroundButtonAction:(id)sender
{
loadingView.hidden = NO;
[SCTwitter postWithMessage:self.messageText.text callback:^(BOOL success, id result) {
loadingView.hidden = YES;
if (success) {
NSLog(@"Message send - %i \n%@", success, result);
Alert(@"Alert", @"Send message in background");
}else {
Alert(@"Alert", @"Not Login");
}
}];
}
- (IBAction)publicTimelineButtonAction:(id)sender
{
loadingView.hidden = NO;
[SCTwitter getPublicTimelineWithCallback:^(BOOL success, id result) {
loadingView.hidden = YES;
if (success) {
//Return array NSDictonary
NSLog(@"%@", result);
Alert(@"Alert", @"Request public timeline success");
}else {
Alert(@"Alert", @"Not Login");
}
}];
}
- (IBAction)userTimelineButtonAction:(id)sender
{
loadingView.hidden = NO;
[SCTwitter getUserTimelineFor:@"lucasc0rrea" sinceID:0 startingAtPage:0 count:200 callback:^(BOOL success, id result) {
loadingView.hidden = YES;
if (success) {
//Return array NSDictonary
NSLog(@"%@", result);
Alert(@"Alert", @"Request user timeline success");
}else {
Alert(@"Alert", @"Not Login");
}
}];
}
- (IBAction)userInformationButtonAction:(id)sender
{
loadingView.hidden = NO;
[SCTwitter getUserInformationCallback:^(BOOL success, id result) {
loadingView.hidden = YES;
if (success) {
//Return array NSDictonary
NSLog(@"%@", result);
Alert(@"Alert", @"Request user information success");
}else {
Alert(@"Alert", @"Not Login");
}
}];
}
- (IBAction)directMessageButtonAction:(id)sender
{
loadingView.hidden = NO;
[SCTwitter directMessage:self.messageText.text to:nil callback:^(BOOL success, id result) {
loadingView.hidden = YES;
if (success) {
//Return array NSDictonary
NSLog(@"%@", result);
}else{
NSLog(@"Error : %@", result);
Alert(@"Alert", result);
}
}];
}
- (IBAction)retweetButtonAction:(id)sender
{
loadingView.hidden = NO;
[SCTwitter retweetMessageUpdateID:nil callback:^(BOOL success, id result) {
loadingView.hidden = YES;
if (success) {
//Return array NSDictonary
NSLog(@"%@", result);
Alert(@"Alert", @"Request retweet success");
}else{
NSLog(@"%@", result);
Alert(@"Alert", @"Error retweet");
}
}];
}
#pragma mark -
#pragma mark - UITextFieldDelegate methods
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- (void)dealloc {
[self setMessageText:nil];
[_background release];
[super dealloc];
}
@end