CooperRS / RMPickerViewController

This is an iOS control for selecting something using UIPickerView in an UIAlertController like manner
MIT License
381 stars 51 forks source link

Webservice - Multiple as well Single Record Added in backend - Added as Array #49

Closed AkshayDegada closed 8 years ago

AkshayDegada commented 8 years ago
    set parameter in Array (for Request parameter in webservice)

—————————————————————— NSMutableArray *arrParameter=[NSMutableArray alloc]init]; arrParameter=…

set Array by assign value like Textfield/ String/ Dictionary etc., in array assign multiple record also.

Array set in dictionary for giving key name for value

—————————————————————————————————————— NSMutableDictionary *dic_Parameter=[[NSMutableDictionary alloc] init]; [dic_Parameter setObject:arrParameter forKey:@“Param1”]; [dic_Parameter setObject:string/array forKey:@"Param2”]; here second line is for pass second array or other key value like EmailID,other Array value etc..

Convert parameter value (your requested parameter) to Json

—————————————————————————————————————————————————————— NSError error = nil; NSData data = [NSJSONSerialization dataWithJSONObject: dic_Parameter options:0 error:&error];

        NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        if (error)
            NSLog(@"%s: JSON encode error: %@", __FUNCTION__, error);

Convert parameter value to Json

—————————————————————————————————————————

        NSString *strURL=[[NSString alloc] init];
        strURL=[NSString stringWithFormat:@“%@“,@“Your URL“];  // webservice URL 

        NSURL *url = [NSURL URLWithString:strURL];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

        [request setHTTPMethod:@"POST"];
        NSString *params = [NSString stringWithFormat:@"json=%@",
                            [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        NSData *paramsData = [params dataUsingEncoding:NSUTF8StringEncoding];
        [request addValue:@"8bit" forHTTPHeaderField:@"Content-Transfer-Encoding"];
        [request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:paramsData];

Response from Webservices as string

—————————————————————————————————————————

NSURLResponse response = nil; NSData returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

        if (error)
            NSLog(@"%s: NSURLConnection error: %@", __FUNCTION__, error);

        // examine the response
             NSString *responseString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
        NSLog(@"responseString: %@",responseString);

Convert parameter value to Json

—————————————————————————————————————————

        if(![responseString isEqualToString:@""])
        {
            NSDictionary *dicFinalGetFacility = [NSJSONSerialization JSONObjectWithData:returnData
                                                                                options:kNilOptions error:&error];

            NSLog(@"dicFinalGetFacility: %@",dicFinalGetFacility);

        }

Final - Complete

————————————————————————————————————————— Final : perform operation on response like give any popup for adding success Records, pop to super view , move to any next view -pushview

CooperRS commented 8 years ago

I think this is not related to RMPickerViewController