-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOtpVC.m
239 lines (204 loc) · 8.57 KB
/
OtpVC.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//
// OtpVC.m
// Islamic
//
// Created by webappsApp on 03/11/16.
// Copyright © 2016 Wifi. All rights reserved.
//
#import "OtpVC.h"
#import "RegisterVC.h"
#import "LogInVC.h"
#define ACCEPTABLE_CHARECTERSMOB @"0123456789+"
#import "MBProgressHUD.h"
@interface OtpVC ()
{
NSString *errorMessage;
NSString *urlstrng;
int hittingCount;
}
@end
@implementation OtpVC
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES];
hittingCount=0;
self.chancesLbl.hidden=YES;
// Do any additional setup after loading the view.
}
- (IBAction)confirmClick:(id)sender {
NSString *otp=self.otpTxtFld.text;
[self.otpTxtFld resignFirstResponder];
if (otp.length==0) {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Please enter OTP value" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
}
else{
NSString *OTP=[[NSUserDefaults standardUserDefaults] objectForKey:@"OTPNumber"];
if ([OTP isEqualToString:otp]) {
[self backToLogin];
// urlstrng=[NSString stringWithFormat:@"%@",self.regLink];
// urlstrng = [urlstrng stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// NSURL *url=[NSURL URLWithString:urlstrng];
// NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
// [request setTimeoutInterval:18000];
// // NSOperationQueue *queue = [[NSOperationQueue alloc] init];
// __block MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
// hud.labelText = @"Loading";
//
// [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
//
// // NSLog(@"Data is: %@",data);
// [hud performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil waitUntilDone:YES];
// hud = nil;
// if (connectionError==nil) {
//
// NSString* newStr1 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// NSLog(@"string from Api: %@",newStr1);
// NSDictionary *jsonData =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
// NSArray *dataArray =[jsonData objectForKey:@"register"];
// if (dataArray.count > 0) {
// NSDictionary *finalDict = [dataArray objectAtIndex:0];
//
// NSLog(@"%@",[finalDict objectForKey:@"status"]);
// if ([[finalDict objectForKey:@"status"] isEqualToString:@"Registration Success"]) {
// // we neeed to aad success link to navigate
//
// [self backToLogin];
// }
// else if ([[finalDict objectForKey:@"status"] isEqualToString:@"Request for registration is already done"]) {
// // we neeed to aad success link to navigate
//
// errorMessage=[NSString stringWithFormat:@"Number Is Already Registered, Please use other number to access the application..!!!"];
// [self errorAlert];
// [self backToLogin];
//
//
// }
// else {
// errorMessage=[NSString stringWithFormat:@"%@ \n Please try again..!!!",[finalDict objectForKey:@"status"]];
// // we neeed to aad success link to navigate
// [self errorAlert];
// [self backToLogin];
// }
//
// }
//
// }
// else {
//
// errorMessage=[NSString stringWithFormat:@"Server Connection Error..!!!"];
// [self errorAlert];
// [hud performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil waitUntilDone:YES];
// hud = nil;
// }
// }];
}
else{
errorMessage=[NSString stringWithFormat:@"Please check Correct OTP value..!!!"];
[self errorAlert];
}
}
}
- (IBAction)resendOtpClick:(id)sender {
if (hittingCount<3) {
NSString *OTP=[[NSUserDefaults standardUserDefaults] objectForKey:@"OTPNumber"];
NSString *urlString = [NSString stringWithFormat:@"http://59.163.89.111:8050/smsbroker/alertsms.php?user=wifijava&pass=javawifi&to=93%@&from=ISLAMIC&msg=Dear customer,OTP:%@ to complete your ISLAMIC APP registration.&msgopt=0&priority=1",self.mobNo,OTP];
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
//[self showWaitingIndicator];
[request setTimeoutInterval:1000];
// NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"%@",data);
if (connectionError==nil) {
NSString* newStr1 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",newStr1);
if([newStr1 isEqualToString:@"\nMessage Submitted."]){
errorMessage=@"OTP sent successfully";
[self errorAlert];
}
else{
errorMessage=newStr1;
[self errorAlert];
}
}
else{
errorMessage=@"Try Again....!";
[self errorAlert];
}
}];
}
else{
errorMessage=@"Please try again some time...!";
[self errorAlert];
[self backToReg];
}
hittingCount++;
NSString *str=[NSString stringWithFormat:@"U have : %d attempts more",3-hittingCount];
self.chancesLbl.hidden=NO;
self.chancesLbl.text=str;
}
- (IBAction)backClick:(id)sender {
[self backToReg];
}
-(void)backToLogin{
__block LogInVC *objVC;
[self.navigationController.viewControllers enumerateObjectsUsingBlock:^(UIViewController *obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[LogInVC class]]) {
objVC=(LogInVC *)obj;
}
}];
[self.navigationController popToViewController:objVC animated:YES];
}
-(void)backToReg{
__block RegisterVC *objVC;
[self.navigationController.viewControllers enumerateObjectsUsingBlock:^(UIViewController *obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[RegisterVC class]]) {
objVC=(RegisterVC *)obj;
}
}];
[self.navigationController popToViewController:objVC animated:YES];
}
-(void)errorAlert{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Islamic" message:errorMessage delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField.tag==301) { //mobile number text field
if([string length]>0)
{
if([textField.text length]<6){
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:ACCEPTABLE_CHARECTERSMOB] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return [string isEqualToString:filtered];
}
return NO;
}
}
return YES;
}
-(void)viewWillDisappear:(BOOL)animated{
self.otpTxtFld.text=nil;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end