2016-05-02 3 views
1

私のアプリケーションで異常なクラッシュが発生しています。このアプリケーションは、目的地のcのバックグラウンドスレッドから自動レイアウトエンジンを変更しています

Mainviewcontroller.m:(別のデリゲートクラスにある)webserviceメソッドを呼び出すメソッドが1つあり、応答が受信されるとメソッドはコールバックを取得しています。

-(IBAction)signupclick:(id)sender{ 
    webservice_obj=[[Webservice alloc] init]; 
    [webservice_obj setDelegate:self]; 
    [webservice_obj Init_withurl:@"register" withparameter:data]; 
} 
-(void)getresponse:(NSMutableDictionary *)response_dictionary{ 
    NSLog(@"dictionary==>%@",response_dictionary); 
    AppDelegate *appDelegate =(AppDelegate*)[[UIApplication sharedApplication]delegate]; 
    [appDelegate.window setRootViewController:appDelegate.frostedViewController]; 
} 

Delegateクラス:Webservice.m

-(void)Init_withurl:(NSString *)name withparameter:(NSMutableDictionary *)reqparameter{ 

    __block NSMutableDictionary *res_dictionary; 
    NSError *error; 
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; 
    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil]; 




    NSURL *url = [NSURL URLWithString:@"http://XXXXXXX"]; 
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url 
                  cachePolicy:NSURLRequestUseProtocolCachePolicy 
                 timeoutInterval:60.0]; 

    [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 
    [request addValue:@"application/json" forHTTPHeaderField:@"Accept"]; 

    [request setHTTPMethod:@"PUT"]; 
    NSData *postData = [NSJSONSerialization dataWithJSONObject:reqparameter options:0 error:&error]; 

    [request setHTTPBody:postData]; 
     NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 
     res_dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; 



      [self fetchresponse:res_dictionary]; 



    }]; 

    [postDataTask resume]; 

} 

-(void)fetchresponse:(NSMutableDictionary*)response{ 
    [[self delegate] getresponse:response]; 
} 

私はコードの下にのGetResponse方法で呼び出されますときに私はエラーを取得しています実行します。エラーの

AppDelegate *appDelegate =(AppDelegate*)[[UIApplication sharedApplication]delegate]; 
    [appDelegate.window setRootViewController:appDelegate.frostedViewController]; 

詳細されています:

このアプリケーションはautolayoutエンジンをバックグラウンドの スレッドから変更しています。これはエンジンの破損や異常なクラッシュを招く可能性があります。この は、将来のリリースで例外を発生させます。 スタック:(0 CoreFoundationの0x00000001127ece65 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000112263deb objc_exception_throw + 48 2 CoreFoundationの0x00000001127ecd9d + [NSExceptionレイズ:フォーマット:] + 205 3ファンデーション0x0000000110504285 _AssertAutolayoutOnMainThreadOnly + 79 4ファンデーション0x0000000110364c1e - [NSISEngine withBehaviors:performModifications:] + 31 5のUIKit 0x00000001111aa1ca - [UIViewの(AdditionalLayoutSupport)_withAutomaticEngineOptimizationDisabledIfEngineExists:] + 58 6のUIKit 0x00000001111a9b66 __57- [UIViewの(AdditionalLayoutSupport)_switchToLayoutEngine:] _ block_invoke + 646 7のUIKit 0x00000001111aa1d3 - [UIViewの(AdditionalLayoutサポート)_withAutomaticEngineOptimizationDisabledIfEngineExists:] + 67 8のUIKit 0x00000001111a989b - [UIViewの(AdditionalLayoutSupport)_switchToLayoutEngine:] + 242 9のUIKit 0x000000011119ae6b - [UIWindow(UIConstraintBasedLayout)_switchToLayoutEngine:] + 81 10のUIKit 0x000000011119af99 - [UIWindow(UIConstraintBasedLayout)_initializeLayoutEngine] + 282 11のUIKit 0x000000011119b022 - [UIWindow(UIConstraintBasedLayout)_layoutEngineCreateIfNecessary] + 62 12のUIKit 0x000000011119b2e3 - [UIWindow(UIConstraintBasedLayout)updateConstraintsIfNeeded] + 60 13のUIKit 0x00000001111aba22 - [UIViewの(AdditionalLayoutSupport)_updateConstraintsAtEngineLevelIfNeeded] + 272 14のUIKit 0x000000011098259e - [UIViewの(階層)_updateCon straintsAsNecessaryAndApplyLayoutFromEngine] + 159 15のUIKit 0x00000001109924cc - [UIViewの(CALayerDelegate)layoutSublayersOfLayer:] + 744 16 QuartzCoreの0x000000010fc3259a - [CALayerのlayoutSublayers] + 146 17 QuartzCore 0x000000010fc26e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 18 QuartzCore 0x000000010fc26cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 19 QuartzCore 0x000000010fc1b475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 20 QuartzCore 0x000000010fc48c0a _ZN2CA11Transaction6commitEv + 486 21 QuartzCore 0x000000010fc48efc _ZN2CA11Transaction14release_threadEPv + 224 22 libsystem_pthread.dylib 0x0000000112ff339c _pthre ad_tsd_cleanup + 470 23 libsystem_pthread.dylib 0x0000000112ff2f78 _pthread_exit + 117 24 libsystem_pthread。dylib 0x0000000112ff1596は、pthread_attr_getschedpolicy + 0 25 libsystem_pthread.dylib 0x0000000112fef375 start_wqthread + 13 )

APIを呼び出し、コールバックとどのようにこのエラーを解決するための操作を行うための標準的な方法を支援し、アドバイスをしてください。

P.s:私はAFNetowrking

+0

を助けるmain thread

dispatch_async(dispatch_get_main_queue(), ^{ AppDelegate *appDelegate =(AppDelegate*)[[UIApplication sharedApplication]delegate]; [appDelegate.window setRootViewController:appDelegate.frostedViewController]; }); 

、などの希望でこのタスク(自動レイアウトエンジンを変更)を行う必要があります - (無効)のGetResponse:(NSMutableDictionary *) response_dictionary'、あなたがメインスレッドにいるかどうかを確認します。もしそうでなければ、それは問題です。メインスレッドでのみUIを変更できます。メインスレッドでGCDを実行する方法については、GCDを参考にしてください。 – Larme

+0

http://stackoverflow.com/questions/28302019/getting-a-this-application-is-modifying-the-autolayout-engine-error –

+0

@Larme返信いただきありがとうございます。しかし、どうすればバックグラウンドスレッドからメインスレッドに移動できますか? –

答えて

1

あなたのクラッシュログを使用したくないが、このアプリケーションは、エンジンの破損や奇妙なクラッシュにつながることができ、バックグラウンドスレッドから自動レイアウトエンジンを変更している

、と述べています。これにより、将来のリリースで例外が発生します。

ですから、これは `で:)

関連する問題

 関連する問題