migrating to AFNetworking 3.0 in objective C

121 Views Asked by At

The code if for checking login data with mysql database using php. the code was working with AFNetworking 2.0 but not I'm migrating to AFNetworking 3.0. I modified the code according to the GitHub documentation.

however I got this error!

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

if I remove this code, the errors goes away!

  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

There are 1 best solutions below

4
Reza Dehnavi On

It seems you don't use dependency manager like CocoaPods. Probably you add AFNetworking library manually. You must check your target name in Show the File in inspector for the .m file of AFHTTPSessionManager.

enter image description here