標籤:
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.
解決方案:
dispatch_async(dispatch_get_main_queue(), ^{ [self presentViewController:alert animated:YES completion:nil]; });
application is modifying the autolayout engine from a background thread解決方案