2016-05-26 34 views
0

私はアプリケーションに関する作業をしていますが、パスワード変更のAPIを使用するとこの警告が表示されます。警告が表示されるのはなぜですか?

このアプリケーションはエンジンの破損や奇妙なクラッシュにつながる可能性のある背景の スレッドから自動レイアウトエンジンを変更しています。この は、将来のリリースで例外を発生させます。

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]; 
     } 




} 

答えて

3

あなたがバックグラウンドスレッドから警告を表示しないでください。

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

はメイン(UI)キューに派遣する必要があります。

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

注スタック・インデックス29 & 28:それはバックグラウンドスレッドで呼び出されている間、アラートを示しているため

[ChangePassword submit:] 

方法は、あなたの問題の元の原因です。

+0

この問題の解決方法 –

+0

私はこれを使用しましたが、同じ警告が再び表示されます –

+0

解決方法は、GCD(グランドセントラルディスパッチ)で読み上げて学習することです。 – gnasher729

関連する問題