post and put and get afnetworking and upload photo also

#import “AFNetworking.h”

#import “IQKeyboardManager.h”

#import “UIImageView+UIActivityIndicatorForSDWebImage.h”

#import “MBProgressHUD.h”

SDWebImage and UIActivityIndicator-for-SDWebImage-master download

Post 

-(IBAction)update_click:(id)sender

{

    

     [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    

//    http://url/api.php?method=update_profile&user_id=67&email=abc@gmail.com&password=Maulik123&avtar=abc.jpg

    

    NSString *st = @”http://url/api/api.php”;

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

   // manager.responseSerializer = [AFHTTPResponseSerializer serializer];

  //  manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@”text/html”];

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@”binary/octet-stream”,@”image/jpg”,@”text/html”,@”text/plain”,nil];

    

    NSDictionary *param = @{@”method”:@”update_profile”,

                            @”user_id”:[de valueForKey:@”user_id”],

                            @”email”:_mail_text.text ,

                            @”password”:_pswd_text.text

                        };

    [manager POST:st parameters:param constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

        UIImage *image =[tempDic valueForKey:UIImagePickerControllerOriginalImage];

        NSData *data1 = UIImageJPEGRepresentation(image, 0.5);

        [formData appendPartWithFileData:data1 name:@”avtar” fileName:@”file1″ mimeType:@”image/jpg”];

        

        

    } success:^(AFHTTPRequestOperation *operation, id responseObject)

     {

         NSLog(@”%@”,responseObject);

         NSArray *arr=responseObject;

         NSLog(@”%lu”,(unsigned long)arr.count);

          [MBProgressHUD hideHUDForView:self.view animated:YES];

            [[NSNotificationCenter defaultCenter] postNotificationName:@”loginComplete” object:nil];

         

     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

         NSLog(@”%@”,error.description);

         

         

     }];

    

}

GET

– (IBAction)saveEvent:(id)sender {

    

    

    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    

    NSUserDefaults *de=[NSUserDefaults standardUserDefaults];

    

   // NSLog(@”%@”,_text_eventedit.text);

   // NSLog(@”%@”,_text_eventedit2.text);

    

  

    

   // NSDate *dateToTExtField=_date_picker_txt.text;

    NSString *dateStr = _date_picker_txt.text;

    

    // Convert string to date object

//    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];

//    [dateFormat setDateFormat:@”dd/MM/YYYY”];

//    NSDate *date = [dateFormat dateFromString:dateStr];

  

    

    NSLog(@”%@”,dateStr);

    NSString *s = [NSString stringWithFormat:@”http://url/api/api.php?method=add_reminder&user_id=%@&reminder_name=%@&reminder_desc=%@&reminder_date=%@&#8221;,[de valueForKey:@”user_id”],_text_eventedit.text,_text_eventedit2.text,_date_picker_txt.text];

    NSLog(@”%@”,s);

    NSLog(@”%@”,_date_picker_txt.text);

    

     NSString *encoded = [s stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    

    

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@”text/html”];

  //  [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    [manager GET:encoded parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

        

       NSDictionary *dic_data1 = responseObject;

        

        NSString *success=[NSString stringWithFormat:@”%@”,[dic_data1 objectForKey:@”status”]];

        NSLog(@”%@”,success);

        

        if ([success isEqualToString:@”Success”])

            

            

        {

            [MBProgressHUD hideHUDForView:self.view animated:YES];

            //[self performSegueWithIdentifier:@”login_segue” sender:sender];

            //Setup_1 *screen1=[self.storyboard instantiateViewControllerWithIdentifier:@”Setup_1″];

            //[self.navigationController pushViewController:screen1 animated:YES];

            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@”Success” message:@”Remainder added successfully” delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil, nil];

            [alert show];

            //NSLog(@”abcd”);

            

        }

        

        

        else

            

            

        {

            

            

            UIAlertView *alert1=[[UIAlertView alloc]initWithTitle:@”Error” message:@”Invalid Email-id” delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil, nil];

            [alert1 show];

        }

        

        

        

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        

    }];

        

     }

PUT

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

        

        //   manager.responseSerializer = [[AFJSONResponseSerializer serializer]init];

        

        manager.requestSerializer = [AFJSONRequestSerializer serializer];

        

        //    [manager.requestSerializer setValue:kSDFParseAPIApplicationId forHTTPHeaderField:@”X-Parse-Application-Id”];

        //    [manager.requestSerializer setValue:kSDFParseAPIKey forHTTPHeaderField:@”X-Parse-REST-API-Key”];

        

        [manager.requestSerializer setValue:@”application/json” forHTTPHeaderField:@”Content-Type”];

        

        

        //    NSDictionary *params = @{@”user[height]”: height,

        

        // { “billing_address”: { “first_name” : “James321”, “last_name” : “anderson” } first_name,last_name, company,address_1,address_2, city,state, postcode, country, phone

        

        //                             @”user[weight]”: weight};

        //    NSDictionary *params=[[NSDictionary alloc]initWithObjectsAndKeys:@”first_name”,txt_fname_main.text,@”last_name”,txt_lname_main.text,@”address_1″,txt_add1_main.text,@”address_2″,txt_add2_main.text,@”city”,txt_city_main.text,@”state”,txt_state_main.text,@”postcode”,txt_zip_main.text,@”country”,txt_cntry_main.text,@”phone”,txt_phone_main.text, nil];

        

        

        //    NSDictionary *params=[[NSDictionary alloc]initWithObjectsAndKeys:@”first_name”,txt_fname_main.text,@”last_name”,txt_lname_main.text,@”address_1″,txt_add1_main.text,@”address_2″,txt_add2_main.text,@”city”,txt_city_main.text,@”state”,txt_state_main.text,@”postcode”,txt_zip_main.text,@”country”,txt_cntry_main.text,@”phone”,txt_phone_main.text, nil];

        NSDictionary *params = @{@”first_name” : txt_fname_shipng.text , @”last_name” : txt_lname_shipng.text , @”address_1″ : txt_addd1_shipng.text , @”address_2″ : txt_add2_shipng.text , @”city” : txt_city_shipng.text , @”state” : txt_state_shipng.text , @”postcode” : txt_zip_shipng.text ,@”country” : txt_cntry_shipng.text };

        

        NSLog(@”%@”,params);

        

        

        NSDictionary *data_collect = @{@”billing_address” : @”” ,@”shipping_address” : params};

        

        NSDictionary *dv =@{@”customer” : data_collect};

        

        NSLog(@”%@”,data_collect);

        

        NSLog(@”%@”,dv);

        

        [manager PUT:[NSString stringWithFormat:@”https://url/wc-api/v2/customers/%d/?consumer_key=ck_0c6ba6ab825a16383313cf4b6cd35917&consumer_secret=cs_895b7fd42f4de2340a18928d448f1e2f&#8221;,app.id_user] parameters:dv success:^(AFHTTPRequestOperation *operation, id responseObject)

         {

             

             NSLog(@”JSON: %@”, responseObject);

        

             

//                 NSLog(@”PAYMENT”);

              payment_view *pc =[self.storyboard instantiateViewControllerWithIdentifier:@”payment_view”];

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

             

             

             

             

             

             

         } failure:^(AFHTTPRequestOperation *operation, NSError *error)

         {

             NSLog(@”Error: %@”, error);

         }];

        

    }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s