警告为何显示?

时间:2016-05-26 10:48:35

标签: ios objective-c

我正在进行应用程序工作,但是当我们使用更改密码的api时会显示此警告。

  

此应用程序正在从后台修改autolayout引擎   线程,这可能导致引擎损坏和奇怪的崩溃。这个   将在未来版本中引发异常。

enter image description here

api正在成功运行,密码已更改,但我不明白为什么会出现此警告。

我正在使用此代码来使用api: -

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
            NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];


     NSURL *url = [NSURL URLWithString:@"http:
xxx.com.api/changepassword"];
                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
                                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                                   timeoutInterval:60.0];

            [request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];


            [request addValue:@"*/*" forHTTPHeaderField:@"Accept"];

            [request setHTTPMethod:@"POST"];

            NSString *mapData = [NSString stringWithFormat:@"regOldPassword=%@&memberId=5&newPassword=%@",string1, string2];

            NSData *postData = [mapData dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

            [request setHTTPBody:postData];

            NSLog(@" Edited data %@", mapData);

            //NSLog(@"email passed id%@",emailstr);


            NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

                if(error == nil)
                {

                    NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
                    NSLog(@"Data = %@",text);


                    NSError *error = nil;
                    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

                    UIAlertView * alert1 = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Password Changes Successfully" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
                    [alert1 show];

                    if(error!=nil)
                    {

                        NSLog(@"error = %@",error);

                    }

                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self checkUserSuccessfullySaved:json];
                    });
                }
                else
                {
                    UIAlertView * alert1 = [[UIAlertView alloc]initWithTitle:@"Unsuccessful" message:@"Failed to change password please try again" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
                    [alert1 show];

                    NSLog(@"Error : %@",error.description);
                }
            }];
            [postDataTask resume];
        }




}

1 个答案:

答案 0 :(得分:3)

您不应该从后台线程显示警告:

\Doctrine\Common\Util\Debug::dump($records);
必须将

分派到主(UI)队列。

UIAlertView * alert1 = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Password Changes Successfully" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert1 show];

注意堆栈索引29& 28:

dispatch_async(dispatch_get_main_queue(), ^{
   UIAlertView *alert1 = ...
   [alert1 show]; 
});

方法是问题的原因,因为它在后台线程上调用时会显示警报。