Friday, 17 June 2016

Json Get ( NSURLConnection )

Json Get ( NSURLConnection )




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 ....


Write Below Code In Info.plist :-


<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>



Write Coding in ViewController.m File ...


#import "ViewController.h"
#import "NSURLConnection_Class.h"

@interface ViewController () < NSURLConnection_CustomDelegate>

@end

@implementation ViewController

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


#pragma mark - Get Data from Json

-(void)getHomeData
{
    //---------------------- Request for Getting School List  ----------------------//
    

    NSURLConnection_Class *obj = [[NSURLConnection_Class alloc] init] ;
    [obj RequestForURL:@"Your URL"];
    obj.delegate = self ;
    
}

#pragma mark - Custom Delegate [ NSURLConnection ]

-(void)connectionFailWithError:(NSError *)error
{
    NSLog(@"Error: %@",error.localizedDescription) ;
}

-(void)connectionFinishWithResponse:(NSString *)responseString
{
    NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:[responseString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil] ;
    
    NSLog(@"%@",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