application is modifying the autolayout engine from a background thread解決方案

NSURLSession *session = [NSURLSession sharedSession];
    __weak id safeSelf = self;
    NSURLSessionDataTask *task = [session dataTaskWithRequest:req completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        self.webData = data;
        if (self.webData) {
            // 若是獲取到了數據
            NSXMLParser *paser = [[NSXMLParser alloc]initWithData:self.webData];
            paser.delegate = self;
            [paser parse];
        }
        
        if ([self.parseResults isEqualToString:@"false"]) {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"登陸失敗" message:@"賬號密碼錯誤" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *action = [UIAlertAction actionWithTitle:@"oops" style:UIAlertActionStyleDefault handler:nil];
            [alert addAction:action];
            //dispatch_async(dispatch_get_main_queue(), ^{
                [self presentViewController:alert animated:YES completion:nil];
            //});
            
        }
        

    }];
    [task resume];
    
[self presentViewController:alert animated:YES completion:nil]語句報錯,信息爲:

application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes.  This will cause an exception in a future release.web

解決方法:session

  dispatch_async(dispatch_get_main_queue(), ^{
                [self presentViewController:alert animated:YES completion:nil];
            });
相關文章
相關標籤/搜索