Friday, 17 June 2016

Json Post ( ASIHTTPRequest )

Json Post



Here Below ASIHTTPRequest Folder Given Below Which Have All File Of Json Post ....


Click Here To Download :-   Download


This Folder Must Be Import in Your Bundle ....


Here ASIHttpRwequest Files Contains Non ARC file So Add (-fno-objc-arc) in Compile Source

ADD Framework :- libz.1.1.3.tbd




Write Coding in ViewController.m File ...


#import "ViewController.h"
#import "ASIFormDataRequest.h"

@interface ViewController () <ASIHTTPRequestDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self sendRequestForSaveSettings];
    
}

#pragma mark - Send Registration Details / ASIHttpRequest

-(void)sendRequestForSaveSettings
{
    
    NSString *str = @"Your URL" ;
    NSString *urlString = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:urlString];
    
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    
    [request setRequestMethod:@"POST"] ;
    [request setDelegate:self] ;
    
    //------- Post Data
    
    [request setPostValue:@"385" forKey:@"user_id"] ;
   
    [request setPostValue:@"YES" forKey:@"Data"] ;
    
    //-------
    
    [request startAsynchronous] ;
    
}

-(void)requestFailed:(ASIHTTPRequest *)request
{
    
    NSError *error = [request error];
    NSLog(@"error : %@" , error);
}

-(void)requestFinished:(ASIHTTPRequest *)request
{
    NSString *responseString = [request responseString];
    NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:[responseString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
    NSLog(@"Responce Dictionary : %@", responseDict);
    
    UIAlertController * alert=   [UIAlertController
                                  alertControllerWithTitle:@""
                                  message:[responseDict objectForKey:@"msg"]
                                  preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction* yesButton = [UIAlertAction
                                actionWithTitle:@"OK"
                                style:UIAlertActionStyleDefault
                                handler:^(UIAlertAction * action)
                                {
                                    //Handel your yes please button action here
                                    
                                }];
    
    [alert addAction:yesButton];
    
    [self presentViewController:alert animated:YES completion:nil];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end



No comments:

Post a Comment