在目标C中迁移到AFNetworking 3.0

时间:2018-08-11 12:28:18

标签: objective-c afnetworking-3

如果使用php使用mysql数据库检查登录数据的代码。该代码与AFNetworking 2.0一起使用,但我没有迁移到AFNetworking 3.0。 我根据GitHub文档修改了代码。

但是我遇到了这个错误!

this is the error image, not sure what it is, and no error is showing on the code!

如果我删除此代码,错误就会消失!

  NSURL *URL = [NSURL URLWithString:stringURL];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:URL.absoluteString parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject)
 {
     // dismiss uiviewController after data loading is done
     [self dismissViewControllerAnimated:NO completion:nil];
     //NSLog(@"success");
     NSDictionary *temp = [[NSDictionary alloc]init ];

     temp = (NSDictionary *)responseObject;
     if(temp.count > 0)
     {
         NSDictionary *TeacherInfo = responseObject[0];
         TeacherName = TeacherInfo[@"Teacher_Name"];
         TeacherID = TeacherInfo[@"Teacher_NO"];
         IsUserAdmin = TeacherInfo[@"IsAdmin"];
         TeacherSubject1 = TeacherInfo[@"Subject1No"];
         TeacherSubject2 = TeacherInfo[@"Subject2No"];
         TeacherSubject3 = TeacherInfo[@"Subject3No"];
         TeacherSubject4 = TeacherInfo[@"Subject4No"];

         //  ViewController *Navigate = (ViewController *)
         //  [self.storyboard instantiateViewControllerWithIdentifier:@"ChoicesViewController"];;
         // [self presentViewController:Navigate animated:YES completion:nil];

     }
     else
     {
         UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"wrong user name or password"
                                                                        message:@"please enter correct data"
                                                                 preferredStyle:UIAlertControllerStyleAlert];

         UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                               handler:^(UIAlertAction * action) {}];

         [alert addAction:defaultAction];
         [self presentViewController:alert animated:YES completion:nil];
     }
 }
 // if failed to connect
     failure:^(NSURLSessionTask *operation, NSError *error)
 {
     UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"connection error"
                                                                    message:@"" preferredStyle:UIAlertControllerStyleAlert];

     UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                           handler:^(UIAlertAction * action) {}];

     [alert addAction:defaultAction];
     [self presentViewController:alert animated:YES completion:nil];
 }]; 

1 个答案:

答案 0 :(得分:0)

似乎您没有使用像CocoaPods这样的依赖管理器。可能是您手动添加了AFNetworking库。您必须在中检查目标名称 Show the File in inspector用于.m的{​​{1}}文件。

enter image description here