'AFHTTPSessionManager' 没有可见的@interface 声明了选择器 'POST:parameters:progress:success:failure:'
No visible @interface for 'AFHTTPSessionManager' declares the selector 'POST:parameters:progress:success:failure:'
我是 objective c 和 IOS 的新手,我正在尝试 post 一些值到 url 并尝试获得响应。
但是我无法编译我的项目,因为我遇到了这个错误
/Users/Desktop/MyIOSApps/Chat System/Chat System/SignInVC.m:92:14: No
visible @interface for 'AFHTTPSessionManager' declares the selector 'POST:parameters:progress:success:failure:'
进口
#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代码
- (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]);
}];
}
谁能帮我解决这个问题。 tnx.
您要找的方法是POST:parameters:success:failure:
。因此,只需从方法调用中删除 progress:nil
即可。整个方法调用如下所示。
[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]);
}];
在 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) {
}];
获取:
[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);
}];
我是 objective c 和 IOS 的新手,我正在尝试 post 一些值到 url 并尝试获得响应。
但是我无法编译我的项目,因为我遇到了这个错误
/Users/Desktop/MyIOSApps/Chat System/Chat System/SignInVC.m:92:14: No visible @interface for 'AFHTTPSessionManager' declares the selector 'POST:parameters:progress:success:failure:'
进口
#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代码
- (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]);
}];
}
谁能帮我解决这个问题。 tnx.
您要找的方法是POST:parameters:success:failure:
。因此,只需从方法调用中删除 progress:nil
即可。整个方法调用如下所示。
[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]);
}];
在 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) {
}];
获取:
[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);
}];