Segue throws an NSInternalInconsistencyException, with an NSURLConnection sendAsynchronousRequest

So, I’m trying to create an application for a website, and I have a Login page, unless it goes to the next view.

This is the code that seems to cause the problem:

NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
 {
     NSString *str=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
     //NSLog(@"%@", str);
     if ([str rangeOfString:@"The username or password you provided is invalid. Please try again."].location == NSNotFound) {
         loginPageStatusLabel.text = @"Correct";
         NSLog(@"Correct Login");

         [self performSegueWithIdentifier:@"toHome" sender:self];


     } else {
         loginPageStatusLabel.text = @"Incorrect";
         NSLog(@"Login Failed");
     }

 }];

* - [UIKeyboardTaskQueue waitUntilAllTasksAreFinished],/SourceCache/UIKit_Sim/UIKit-2935.137/Keyboard/UIKeyboardTaskQueue.m:368 2014-05-11 00: 06: 51.426 LoginTests [3381: 3e03] * - "NSInternalInconsistencyException", : '- [UIKeyboardTaskQueue waitUntilAllTasksAreFinished]' . ' waitUntilAllTasksAreFinished] ' .

, "". Segue , , , , .

Obj-C, , , , .

!

+4
1

, queue, , , , [NSOperationQueue mainQueue] ( ). queue , , , UI , .

, , , . .

[NSOperationQueue mainQueue] :

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
 {
     if (!data) {
         // for example, no internet connection or your web server is down

         NSLog(@"request failed: %@", error);
         return;
     }

     if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
         int statusCode = [(NSHTTPURLResponse *)response statusCode];

         if (statusCode != 200) {
             // for example, 404 would mean that your web site said it couldn't find the URL
             // anything besides 200 means that there was some fundamental web server error

             NSLog(@"request resulted in statusCode of %d", statusCode);
             return;
         }
     }

     // if we got here, we know the request was sent and processed by the web server, so now
     // let see if the login was successful.

     NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

     // I'm looking for "Welcome" ... I doubt that right (but I don't have access to 
     // your web server, so I'm guessing). But the idea is that you have to find whatever
     // appears after successful login that is not in the response if login failed

     if ([responseString rangeOfString:@"Welcome"].location != NSNotFound) {
         loginPageStatusLabel.text = @"Correct";
         NSLog(@"Correct Login");

         [self performSegueWithIdentifier:@"toHome" sender:self];
     } else {
         loginPageStatusLabel.text = @"Incorrect";
         NSLog(@"Login Failed");
     }
 }];
+3

Source: https://habr.com/ru/post/1540088/


All Articles