First Create New File webServiceParsing Class
webServiceParsing.h
webServiceParsing.h
#import <Foundation/Foundation.h>
@interface webServiceParsing : NSObject
-(id) getDataFromURLString :(NSString*)urlString;
@end
webServiceParsing.m
#import "webServiceParsing.h"
@implementation webServiceParsing
-(id) getDataFromURLString :(NSString*)urlString
{
NSURL *url = [NSURL URLWithString:urlString];
NSError* error = nil;
NSData *data = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:&error];
if (error) {
NSLog(@"%@", [error localizedDescription]);
} else {
NSLog(@"Data has loaded successfully.");
}
if (data == nil)
{
[self performSelectorOnMainThread:@selector(serverError) withObject:nil waitUntilDone:YES];
return nil;
}
else
{
NSError *err;
id result=[NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error: &err];
return result;
}
}
-(void)serverError
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error !!!" message:@"Server Error" delegate:nilcancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
@end
signupControoler.m
#import "webServiceParsing.h"
-(void)JSONMethod
{
//txtfirstname,txtlastname,txtEmail,txtusernamename,txtpassword,txtconfirmpass;
NSString *urlString = [NSString stringWithFormat:@"http://192.168.1.253:81/roto/registration.php?first_name=%@&last_name=%@&email=%@&username=%@&password=%@",txtfirstname.text,txtlastname.text,txtEmail.text,txtusernamename.text,txtconfirmpass.text];
response = [[webServiceParsing alloc] getDataFromURLString:urlString];
}
-(IBAction)Signupbutton:(id)sender
{
[self JSON];
if([[response objectForKey:@"successful"] isEqualToString:@"true"]){
loginview1 =[[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
[[self navigationController] pushViewController:loginview1 animated:YES];
}
else{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Failed" message:[response objectForKey:@"message"] delegate:nilcancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}
}
No comments:
Post a Comment