I have a webservices url which appends with securecode. When I enter correct securecode for example to say abcd, then application will load. when I entered wrong secure code, I need to show alert as 'wrong securecode'. My code is here:
- (void) alertStatus:(NSString *)msg :(NSString *)Title:(int)tag
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:Title
message:msg
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
if(tag)
alertView.tag = tag;
[alertView show];
}
-(IBAction)loginClicked:(id)sender {
@try {
if([[txtsecurecode text] isEqualToString:@""] ) {
[self alertStatus:@"Please enter Access code" :@"Login Failed!":0];
} else {
NSString *post =[[NSString alloc] initWithFormat:@"txtsecurecode=%@",[txtsecurecode text]];
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://my example.com/Accountservice/Security/ValidAccess?accesscode=%@&type=1",txtsecurecode.text]];
NSString *responseData = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding];
responseData is the reference where I am getting response from the web services url.so below getting response, I need to keep alert.
How can I keep alert in this case showing alert when entered wrong secure code?
Try to use this code...
-(IBAction)loginClicked:(id)sender {
@try {
if([[txtsecurecode text] isEqualToString:@""] ) {
[self alertStatus:@"Please enter Access code" :@"Login Failed!":0];
} else {
NSString *post =[[NSString alloc] initWithFormat:@"txtsecurecode=%@",[txtsecurecode text]];
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://my example.com/Accountservice/Security/ValidAccess?accesscode=%@&type=1",txtsecurecode.text]];
/*UPDATED*/
NSString *responseData = [[NSString alloc]initWithContentsOfURL:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding error:nil];
if([responseData isEqualToString:@""])
{
[self alertStatus:@"Please enter valid Access code" :@"Login Failed!":0];
}
else
{
//Your code for handling the response data
}
}
}
}