Registration_Numberpad

In IOS 7

.H File

@property (strong, nonatomic) IBOutlet UILabel *numberDisplay;

@property (strong, nonatomic) IBOutlet UIView *backView;

@property (nonatomic) BOOL typingNumber;

@property (nonatomic, copy) NSString *operation;

– (IBAction)numberPressed:(UIButton *)sender;

.M File

@synthesize

numberDisplay           =_numberDisplay,

typingNumber            =_typingNumber ;

– (IBAction)numberPressed:(UIButton *)sender {

    NSString *number = sender.currentTitle;

    if (_typingNumber)

    {

        _numberDisplay.text = [_numberDisplay.text

                               stringByAppendingString:number];

    } else

    {

        _numberDisplay.text = number;

        _typingNumber= YES;

    }

}

Storyboard.Xib

Drag Down 0 to 9 Button and Give up Touch up one Action to all Button and Set Constrains .

PopToView as Selected View Like This…

-(IBAction)btnHome_clicked:(id)sender

{

    for (int i=0; i<[self.navigationController.viewControllers count]; i++)

    {

        if ([NSStringFromClass([[self.navigationController.viewControllers objectAtIndex:i] class]) isEqualToString:@”ProductListViewController”])

        {

            [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:i] animated:YES];

        }

    }

}

Detail Product(Desc) From Json in iphone

– (void)viewDidLoad

{

    [super viewDidLoad];

      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detailReceived:) name:@”detail” object:nil];

 

    objMLeadServices = [[MLeadService alloc]init];

    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];

    [dic setValue:strID forKey:@”productid”];

 

    [objMLeadServices WS_Detail:dic];

}

 

– (void) detailReceived:(NSNotification *) notification

{

    dicDetails = [[NSDictionary alloc]init];

    dicDetails = [objMLeadServices handleWS_Detail:notification];

    

    NSLog(@”dicDetails : %@”,dicDetails);

  

    productLabel.text = [[[dicDetails valueForKey:@”productlistdetails”] objectAtIndex:0] valueForKey:@”product_name”];

    productLabel1.text = [[[dicDetails valueForKey:@”productlistdetails”] objectAtIndex:0] valueForKey:@”product_name”];

    lblAvaStock.text = [NSString stringWithFormat:@”(Only %@ in stock)”,[[[dicDetails valueForKey:@”productlistdetails”] objectAtIndex:0] valueForKey:@”product_quantity”]];

    lblDesc.text = [[[dicDetails valueForKey:@”productlistdetails”] objectAtIndex:0] valueForKey:@”product_desc”];

    lblDesc.numberOfLines = 0;

    [lblDesc setLineBreakMode:NSLineBreakByWordWrapping];

    float hei;

    hei = [AppDelegate getHeightOfString:lblDesc.text withFont:lblDesc.font andWidth:lblDesc.frame.size.width]; //Static Methods in Appdelegate….. this is in Blog also

    

    NSLog(@”hei : %f”,hei);

    lblDesc.frame = CGRectMake(20, 196, 280, hei);

    [scrldetailView setContentSize:CGSizeMake(scrldetailView.frame.size.width, scrldetailView.frame.size.height+hei)];

    [imgV loadImageFromURL:[NSURL URLWithString:[[[dicDetails valueForKey:@”productlistdetails”] objectAtIndex:0] valueForKey:@”product_img”]]];

 

}

 

Product List From Json in iphone

– (void)viewDidLoad

{

    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(listReceived:) name:@”list” object:nil];

    objMLeadServices = [[MLeadService alloc]init];

    [objMLeadServices WS_List];

    

}

– (void) listReceived:(NSNotification *) notification

{

    NSDictionary *dicData = [objMLeadServices handleWS_List:notification];

    NSLog(@” dicData : %@”,dicData);

    

    arrData = [[NSMutableArray alloc]init];

    arrData = [dicData valueForKey:@”productlist”];

    [arrData retain];

    [tbl reloadData];

}

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

 // Product Name& Product Desc in Label  On Cell 

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

label = [[UILabel alloc]initWithFrame:CGRectMake(100, 10, 100, 25)];

    label.text = [[arrData objectAtIndex:indexPath.row] valueForKey:@”product_name”];

    label.textColor=[UIColor blackColor];

    label.font = [UIFont boldSystemFontOfSize:20.0f];

    label.backgroundColor = [UIColor clearColor];

    [cell.contentView addSubview:label];

    

    label2=[[UILabel alloc]initWithFrame:CGRectMake(100, 35,180, 38)];

    label2.text = [[arrData objectAtIndex:indexPath.row] valueForKey:@”product_desc”];

    label2.textColor = [UIColor grayColor];

    label2.numberOfLines = 0;

    label2.backgroundColor = [UIColor clearColor];

    label2.font = [UIFont systemFontOfSize:16.0f];

    [cell.contentView addSubview:label2];

 }

– (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

// Go For NextPage With ID

    DetailProductViewController *objDetail=[[DetailProductViewController alloc]initWithNibName:@”DetailProductViewController” bundle:nil];

    objDetail.strID = [[arrData objectAtIndex:indexPath.row] valueForKey:@”id”];

     [self.navigationController pushViewController:objDetail  animated:YES];

}

 

Registration Data From JsonParsing

WebServiceConnection.h

#import “JSON.h”

@interface WebServiceConnection : NSURLConnection {

NSMutableData *responseData;

NSString *NotificationName;

    

    id delegate;

    

}

@property(nonatomic,readwrite) int WebSeviceFor;

@property(nonatomic,retain) id delegate;

– (id)initWithJSONKey:(NSString*)strJSONKey JSONValues:(NSDictionary*)dictJSONValues URL:(NSString*)strURL NotificationName:(NSString*)strNotificationName;

WebServiceConnection.m

@synthesize WebSeviceFor, delegate;

#pragma mark –

#pragma mark Init Method

– (id)initWithJSONKey:(NSString*)strJSONKey JSONValues:(NSDictionary*)dictJSONValues URL:(NSString*)strURL NotificationName:(NSString*)strNotificationName

{

————-

WebService.h

#import “WebServiceConnection.h”

@interface MLeadService : NSObject

{

AppDelegate *appDelegate;

}

– (void)authenticationWithWebService:(NSMutableDictionary*)dict;

– (NSString *)handleWebServiceResponseforAuth:(NSNotification*)notification;

– (void)WS_List;

– (NSDictionary *)handleWS_List:(NSNotification*)notification;

– (void)WS_Detail:(NSMutableDictionary*)dict;

– (NSDictionary *)handleWS_Detail:(NSNotification*)notification;

NSMutableURLRequest *request;

NotificationName = strNotificationName;

if(dictJSONValues!=nil)

{

//NSLog(@”%@”,[dictJSONValues JSONFragment]);

NSString *requestString = [NSString stringWithFormat:@”%@=%@”,strJSONKey,[dictJSONValues JSONFragment]];

NSLog(@”\n%@ \nrequest string: %@”,strURL, requestString);

NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]];

request = [[NSMutableURLRequest alloc] initWithURL

  [NSURL URLWithString:[strURL stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];

[request setHTTPMethod: @”POST”]; 

[request setHTTPBody: requestData];

}

else 

{

request = [[NSMutableURLRequest alloc] initWithURL

  [NSURL URLWithString:[strURL stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];

}

responseData = [[NSMutableData data] retain];

[super initWithRequest:request delegate:self];

   // NSLog(@”STEP 8″);

[request release];

return self;

}

-(void) dealloc

{

[responseData release];

[super dealloc];

}

#pragma mark –

#pragma mark delegate Methods

– (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{

[responseData setLength:0];

}

– (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{

[responseData appendData:data];

}

– (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{

    if ([delegate respondsToSelector:@selector(didCompleteRequest:withData:)]) {

        [delegate performSelector:@selector(didCompleteRequest:withData:) withObject:NotificationName withObject:nil];

    } else {

        [[NSNotificationCenter defaultCenter] postNotificationName:NotificationName object:nil];

    }

}

– (void)connectionDidFinishLoading:(NSURLConnection *)connection{

//NSLog(@”STEP 6″);

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

NSLog(@”response string: \n\n %@ \n\n “, responseString);

    if ([delegate respondsToSelector:@selector(didCompleteRequest:withData:)])

    {

        [delegate performSelector:@selector(didCompleteRequest:withData:) withObject:NotificationName withObject:responseString];

    } else {

        [[NSNotificationCenter defaultCenter] postNotificationName:NotificationName object:responseString];

    }

[responseString release];

    //NSLog(@”STEP 5″);

}

– (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {

return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];

}

– (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {

if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])

//if ([trustedHosts containsObject:challenge.protectionSpace.host])

[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];

[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];

}

————

WebService.m

 

– (id)init {

[super init];

appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];

return self;

}

#pragma mark –

#pragma mark Login

/***– Login Service –***/

– (void)authenticationWithWebService:(NSMutableDictionary*)dict

{

WebServiceConnection *objWebServiceCon = [[WebServiceConnection alloc] initWithJSONKey:@”registration” JSONValues:dict

                                        URL:RegisterUrl  NotificationName:@”checkAuth”];

[dict release];

[objWebServiceCon release];

}

– (NSString *)handleWebServiceResponseforAuth:(NSNotification*)notification

{

NSString * isLoginId =@””;

if ([notification object] != nil)

    {

NSDictionary *dict = [[notification object] JSONValue];

NSDictionary *respDict = [dict objectForKey:@”registerUser”];

if ([[respDict objectForKey:@”status”] isEqualToString:@”YES”])

        {

            isLoginId = [respDict objectForKey:@”userId”];

}

        else

        {

            isLoginId = @””;

}

}

    [appDel removeWaitingView];

return isLoginId;

}

– (void)WS_List

{

    

    WebServiceConnection *objWebServiceCon = [[WebServiceConnection alloc] initWithJSONKey:@”getproductlist”

JSONValues:nil

                                                                                       URL:ProductListUrl

  NotificationName:@”list”];

[objWebServiceCon release];

    

}

– (NSDictionary *)handleWS_List:(NSNotification*)notification

{

if ([notification object] != nil)

    {

NSDictionary *dict = [[notification object] JSONValue];

NSDictionary *respDict = [dict objectForKey:@”getproductlist”];

if ([[respDict objectForKey:@”status”] isEqualToString:@”YES”])

        {

            return respDict;

}

}

return nil;

}

– (void)WS_Detail:(NSMutableDictionary*)dict

{

WebServiceConnection *objWebServiceCon = [[WebServiceConnection alloc] initWithJSONKey:@”getproductdetails”

JSONValues:dict

                                                                                       URL:ProductDetails

  NotificationName:@”detail”];

    [dict release];

[objWebServiceCon release];

}

– (NSDictionary *)handleWS_Detail:(NSNotification*)notification

{

    if ([notification object] != nil)

    {

NSDictionary *dict = [[notification object] JSONValue];

NSDictionary *respDict = [dict objectForKey:@”getproductlistdetails”];

if ([[respDict objectForKey:@”status”] isEqualToString:@”YES”])

        {

            return respDict;

}

}

return nil;

}

= = = = = = = = = = = = = = = = = = = = = = (  How To Used WebServices  )  = = = = = = = = = = = = = = = = = = = = = =

RootViewController.h

#import “webService.h”

{

webService *ObjWebService;

}

RootViewController.m

-(IBAction)ActionSend:(id)sender

{

      objMLeadServices = [[MLeadService alloc]init];

// Here Alert Validation of TextField From Above Blogs

      [objMLeadServices authenticationWithWebService:dic];

 }

– (void)viewDidLoad

{

           [super viewDidLoad];

           [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRegistorSuccess:) name:@”checkAuth” object:nil];

}

 

// If Registration Success Then

– (void) didRegistorSuccess:(NSNotification *) notification

{

    NSString *userid=[objMLeadServices handleWebServiceResponseforAuth:notification];

    NSLog(@”User Id:- %@”,userid);

    if([userid intValue]>0)

    {

        NSUserDefaults *defaultUser=[NSUserDefaults standardUserDefaults];

        [defaultUser setValue:userid  forKey:SavedUserId];

        [defaultUser synchronize];

        

    // Go Next Page Here ………….  

      ProductListViewController *obj_product=[[ProductListViewController alloc]initWithNibName:@”ProductListViewController” bundle:nil];

        [self.navigationController pushViewController:obj_product animated:YES];

        [obj_product release];

    }

    else

    {

             [AppDelegate setAlert:@”” withMessage:@”Registration Failed” withDelegate:self withTag:102 andButtons:@”OK”,nil];

    }

}

 
 

Validation Message at Registration Where JsonParsing

1) First Of All Add Validation Class Validation .h &.m

2)#import “Validate.h”

 

-(IBAction)ActionSend:(id)sender

{

    objMLeadServices = [[MLeadService alloc]init]; // Json WebServices

    NSString *str=@””;

    if([Validate isEmpty:txtForename.text])

    {

        str=@”Please Enter Forname”;

    }

    else if([Validate isEmpty:txtSurname.text])

    {

         str=@”Please Enter Surname”;

    }

    else if([Validate isEmpty:txtEmail.text])

    {

        str=@”Please Enter Email Address”;

    }

    else if([Validate isEmpty:txtTelephone.text])

    {

        str=@”Please Enter Password”;

    }

    else if([Validate isEmpty:txtMobile.text])

    {

         str=@”Please Enter Mobile Number”;

    }

    else if([Validate isEmpty:txtAddress1.text] && [Validate isEmpty:txtAddress2.text]&&[Validate isEmpty:txtAddress3.text] && [Validate isEmpty:txtAddress4.text])

    {

        str=@”Please Enter Address”;

    }

    else if([Validate isEmpty:txtCountry.text])

    {

         str=@”Please Enter Country”;

    }

    else if([Validate isEmpty:txtPostcode.text])

    {

        str=@”Please Enter Postal Code”;

    }

    else if(![Validate isValidEmailAddress:txtEmail.text])

    {

         str=@”Please Enter Valid Email Address”;

    }

    else if(![Validate isNumbersOnly:txtMobile.text])

    {

          str=@”Please Enter Valid Mobile Number “;

    }

    else if(![Validate isNumbersOnly:txtPostcode.text])

    {

         str=@”Please Enter Valid Postal code”;

    }

    if ([str length]>0)

    {

        [AppDelegate setAlert:@”Info” withMessage:str  withDelegate:self withTag:102 andButtons:@”OK”, nil];

    }

    else

    {

        

        NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];

        [dic setValue:txtForename.text forKey:@”name”];

        [dic setValue:txtSurname.text forKey:@”username”];

        [dic setValue:txtEmail.text forKey:@”email”];

        [dic setValue:txtTelephone.text forKey:@”password”];

        [dic setValue:txtComapany.text forKey:@”company”];

        [dic setValue:txtAddress1.text forKey:@”address1″];

        [dic setValue:txtAddress2.text forKey:@”address2″];

        [dic setValue:txtAddress3.text forKey:@”address3″];

        [dic setValue:txtAddress4.text forKey:@”address4″];

        [dic setValue:txtPostcode.text forKey:@”postal”];

        [dic setValue:txtCountry.text forKey:@”country”];

        [dic setValue:txtTelephone.text forKey:@”telephone”];

        [dic setValue:txtMobile.text forKey:@”mobile”];

    

        [appDel showWaitingView];

        [objMLeadServices authenticationWithWebService:dic];

   }

}

 

Soap Xml in iphone

AddParser.h

#define AD_PARSING 200

@protocol BannerAdParserFinished

-(void) FoundChannel:(NSString *)userId WithError:(NSError *) error;

@end

 

@interface BannerAdParser : NSXMLParser <NSXMLParserDelegate>{

    NSMutableArray * aryChannel;

    NSMutableDictionary * dictChannel;

    NSString * strtemp;

    NSMutableString * strBannerAd;

    NSMutableData *webData;

    

  id <BannerAdParserFinished>  del;

    

}

@property int parsingType;

-(void)getBannerAdparserwithUserId:(NSString *)userId;

@property(nonatomic,strong) id <BannerAdParserFinished>  del;

@end

 

AddParser.m

@synthesize del;

 

-(id) initWithData:(NSData *)data{

    if(self=[super initWithData:data]){

        super.delegate = self;

        return self;

    }

    return nil;

}

 

– (void)parserDidStartDocument:(NSXMLParser *)parser{

    

}

 

– (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict{

    if([elementName isEqualToString:@”return”])

    {

        dictChannel=[[NSMutableDictionary alloc]init];

    }

    else if([elementName isEqualToString:@”adDuration”] ||[elementName isEqualToString:@”adId”] ||[elementName isEqualToString:@”expirationTime”] ||[elementName isEqualToString:@”expirationTime”]||[elementName isEqualToString:@”gameId”]||[elementName isEqualToString:@”sponsorId”]||[elementName isEqualToString:@”urlLink”])

    {

        strBannerAd=[[NSMutableString alloc]init];

    }

}

 

– (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{

    [strBannerAd appendString:string];

}

 

– (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{

    [del FoundChannel:nil WithError:parseError];

}

 

– (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{

    

    if([elementName isEqualToString:@”return”])

    {

        

    }

    else if ([elementName isEqualToString:@”adDuration”] ||[elementName isEqualToString:@”adId”] ||[elementName isEqualToString:@”expirationTime”] ||[elementName isEqualToString:@”expirationTime”]|| [elementName isEqualToString:@”gameId”]||[elementName isEqualToString:@”sponsorId”]||[elementName isEqualToString:@”urlLink”])

    {

              [dictChannel setValue:strBannerAd forKey:elementName];

}

 }

 

-(void)getBannerAdparserwithUserId:(NSString *)userId;

{

    self.parsingType=AD_PARSING;

    NSString *soapMessage =[NSString stringWithFormat:@”<soapenv:Envelope xmlns:soapenv=\”http://schemas.xmlsoap.org/soap/envelope/\” xmlns:web=\”http://webservice.fancheer.com/\”>”

                            “<soapenv:Header/>”

                            “<soapenv:Body>”

                            “<web:getBannerAd>”

                            “<userId>%@</userId>”

                            “</web:getBannerAd>”

                            “</soapenv:Body>”

                            “</soapenv:Envelope>”,userId];

    

    NSLog(@”BannerAdService—-Request soapMessage %@”,soapMessage);

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@”%@%@”,kUrl,@”fanCheer/BannerAdService”]]

    ;

//NSURL *url = [NSURL URLWithString:@”http://182.73.38.29:8080/fanCheer/BannerAdService“];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];

NSString *msgLength = [NSString stringWithFormat:@”%d”, [soapMessage length]];

 

[theRequest addValue: @”text/xml; charset=utf-8″ forHTTPHeaderField:@”Content-Type”];

[theRequest addValue: @”” forHTTPHeaderField:@”SOAPAction”];

[theRequest addValue: msgLength forHTTPHeaderField:@”Content-Length”];

[theRequest setHTTPMethod:@”POST”];

[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

 

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

 

if(theConnection)

{

        webData = [[NSMutableData data] retain];

    }

else

{

NSLog(@”theConnection is NULL”);

}

}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

{

    [webData setLength: 0];

}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

{

    [webData appendData:data];

}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

{

    NSLog(@”ERROR with theConenction %@”,error.description);

    [connection release];

    [webData release];

}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection

{

    NSLog(@”DONE   Received Bytes: %d”, [webData length]);

    NSString *str = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];

    NSLog(@”BannerAd Response = %@”, str);

    [self initWithData:webData];

    self.delegate = self;

    [self parse];

    

    [connection release];

    [webData release];

}

———————-   How to Call Soap  XmlParser     —————————-

#import “BannerAdParser.h”

-(void)ViewdidLoad

 {

       BannerAdParser *xmlParser=[[BannerAdParser alloc]init];

       xmlParser.del=self;

      [xmlParser getBannerAdparserwithUserId:@”15″];

}