I am currently stuck on the part where user use his username and password to view his data. I did try every piece of information on this website to find out how to make it work with no luck so far if anyone can point me in the right direction I’ll be grateful.
here is my .h file:
#import <UIKit/UIKit.h>
@interface ePaymentLoginViewController : UIViewController {
IBOutlet UITextField *__weak usernameField;
IBOutlet UITextField *__weak passwordField;
IBOutlet UIButton *__weak loginButton;
IBOutlet UIActivityIndicatorView *__weak loginIndicator;
}
@property (weak, nonatomic) UITextField *usernameField;
@property (weak, nonatomic) UITextField *passwordField;
@property (weak, nonatomic) UIButton *loginButton;
@property (weak, nonatomic) UIActivityIndicatorView *loginIndicator;
- (IBAction) login: (id) sender;
- (IBAction)backButton:(id)sender;
- (IBAction)cancelButton:(id)sender;
@end
here is my .m file:
#import "ePaymentLoginViewController.h"
@interface ePaymentLoginViewController ()
@end
@implementation ePaymentLoginViewController
@synthesize usernameField;
@synthesize passwordField;
@synthesize loginButton;
@synthesize loginIndicator;
- (IBAction) login: (id) sender
{
NSString *post =[NSString stringWithFormat:@"%@/%@",usernameField.text, passwordField.text];
NSString *hostStr = @"http://ourserver/mobilepay/MobilePayService.svc/verify/%@/%@";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
if([serverOutput isEqualToString:@"text/json"]){
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Congrats" message:@"You are authorized" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alertsuccess show];
} else {
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Login Failed" message:@"Username or Password Incorrect" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alertsuccess show];
loginIndicator.hidden = TRUE;
loginButton.enabled = TRUE;
[loginIndicator startAnimating];
}
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren’t in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
-(IBAction)backButton:(id)sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(IBAction)cancelButton:(id)sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
after successful login this is how the url should look and it will send JSON data
http://ourserver/mobilepay/MobilePayService.svc/verify/user123/test123
{
"Table": [
{
"comp_filenum": 1006842,
"comp_namar": "username123",
"comp_civid": "100000"
}
],
"Table1": [
{
"tran_num": 30301,
"inst_val": 1725,
"balance": 3450,
"late_amount": 3450,
"late_inst_no": 2,
"legal_status": 0,
"baloon_balance": 0,
"late_bal_no": 0,
"remain_bal_no": 0,
"clienttype": 2,
"filenumber": 1006842,
"customername": "username123",
"civilid": "100000",
"saleprice": 82800,
"costprice": 66005,
"last_receiptnumber": "e22512",
"last_paydate": "2012-05-02T00:00:00",
"last_payamount": 1725,
"paidamount": 79350,
"remaininginstallment": 16
},
So what am i doing wrong at this point and what is the right way to do it.
Try with below line :