8

I am new to objective c and IOS, I'm trying to post some values to a url and trying to get the response.

but I can't compile my project because, i'm having this error

/Users/Desktop/MyIOSApps/Chat System/Chat System/SignInVC.m:92:14: No visible @interface for 'AFHTTPSessionManager' declares the selector 'POST:parameters:progress:success:failure:'

Imports

#import "SignInVC.h"
#import <QuartzCore/QuartzCore.h>
#import "ApplicationEnvironmentURL.h"
#import "Reachability.h"
#import "AFNetworking/AFNetworking.h"
#import "MBProgressHUD/MBProgressHUD.h"
#import "AppDelegate.h"

Objective-c Code

- (void)submitLoginRequest:(NSString *)email password:(NSString *)password {

    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];

    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:email forKey:@"Email"];
    [dict setValue:password forKey:@"Password"];

    NSLog(@"Login dicxtionary : %@", dict);
    MBProgressHUD *hud;
    hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.label.text = @"Please wait. Logging in...";

    [hud showAnimated:YES];


    // send user login data to hosting via AFHTTP Async Request in AFNetworking
    [manager POST:BASEURL parameters:dict progress:nil success:^(NSURLSessionTask *task, id responseObject) {

        [hud hideAnimated:YES];
        // Login response validation
        if (responseObject == [NSNull null]) {
            [self showMessage:@"Login Failed" Message:@"Unable to login. Please try again!"];
        }else {
            //NSError *error = nil;
            NSLog(@"response type : %@", NSStringFromClass([responseObject class]));
            //NSDictionary *response = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
            [self checkResultValue:(NSDictionary *)responseObject];
        }

    } failure:^(NSURLSessionTask *task, NSError *error) {

        NSLog(@"AFHTTPSession Failure : %@", [error localizedDescription]);
    }];

}

Can someone help me to fix this issue. tnx.

2 Answers 2

10

The method you are looking for is POST:parameters:success:failure:. So simply remove the progress:nil from the method call. The whole method call would be look like below.

    [manager POST:BASEURL parameters:dict success:^(NSURLSessionTask *task, id responseObject) {

        [hud hideAnimated:YES];
        // Login response validation
        if (responseObject == [NSNull null]) {
            [self showMessage:@"Login Failed" Message:@"Unable to login. Please try again!"];
        }else {
            //NSError *error = nil;
            NSLog(@"response type : %@", NSStringFromClass([responseObject class]));
            //NSDictionary *response = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
            [self checkResultValue:(NSDictionary *)responseObject];
        }

    } failure:^(NSURLSessionTask *task, NSError *error) {

        NSLog(@"AFHTTPSession Failure : %@", [error localizedDescription]);
    }];
3
  • This work's for me in Stripe iOS implementation, thanks! Mar 23, 2018 at 0:01
  • This was extremely helpful! Thank you.
    – Brittany
    Nov 8, 2018 at 18:34
  • Instance method '-GET:parameters:success:failure:' not found (return type defaults to 'id') fot GET using the v4
    – sejn
    Mar 2, 2022 at 9:29
9

In AFNetworking 4.0

POST:

[manager POST:baseUrl parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];

GET:

[manager GET:baseUrl parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
      NSLog(@"getDeviceScanResults: failure: %@", error.localizedDescription);
}];
1
  • nstance method '-GET:parameters:success:failure:' not found (return type defaults to 'id') fot GET using the v4
    – sejn
    Mar 2, 2022 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.