2016-12-27 88 views
2

我是新来的目标c和IOS,我试图发布一些值到一个URL,并试图获得响应。没有可见@interface为'AFHTTPSessionManager'声明选择'POST:参数:进展:成功:失败:'

,而是因为,我遇到这个错误

/用户/桌面/ MyIOSApps /聊天系统,我不能编译我的项目/聊天系统/ SignInVC.m:92:14:无 可见@interface为 'AFHTTPSessionManager' 宣布选择 'POST:参数:进展:成功:失败:'

进口

#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。

回答

5

您正在查找的方法是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]); 
    }]; 
+1

抱歉,延迟,它工作正常。 TNX。 –

+0

@SathyaBaman欢迎伴侣:) –

相关问题