Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 此应用程序正在从objective c中的后台线程修改autolayout引擎_Ios_Objective C_Delegates_Nsurlsession - Fatal编程技术网

Ios 此应用程序正在从objective c中的后台线程修改autolayout引擎

Ios 此应用程序正在从objective c中的后台线程修改autolayout引擎,ios,objective-c,delegates,nsurlsession,Ios,Objective C,Delegates,Nsurlsession,我的应用程序中出现了奇怪的崩溃 Mainviewcontroller.m:有一个方法调用webservice方法(在另一个委托类中),然后当收到响应时,该方法将得到回调 -(IBAction)signupclick:(id)sender{ webservice_obj=[[Webservice alloc] init]; [webservice_obj setDelegate:self]; [webservice_obj Init_withurl:@"register"

我的应用程序中出现了奇怪的崩溃

Mainviewcontroller.m:有一个方法调用webservice方法(在另一个委托类中),然后当收到响应时,该方法将得到回调

-(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];
}
委托类: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];
错误的详细信息如下:

此应用程序正在后台修改自动布局引擎 线程,这可能导致引擎损坏和奇怪的崩溃。这 将在将来的版本中导致异常。 堆栈:( 0 CoreFoundation 0x00000001127ece65例外预处理+165 1 libobjc.A.dylib 0x0000000112263deb objc_异常_抛出+48 2 CoreFoundation 0x00000001127ecd9d+[N异常提升:格式:][205 3基金会0x000 000 0110 50428 5 4基金会0x000 000 010364C1E - [ NSISEngulee的行为:PrimultExp修改:] + 31 5 UIKit 0x00000001111aa1ca-[UIView(附加布局支持)\u具有自动工程优化功能,不允许DIFengineexists:+58 6 UIKit 0x0000000111A9B66 \uuuU 57-[UIView(附加布局支持)\u switchToLayoutEngine:]\u block\u invoke+646 7 UIKit 0x00000001111aa1d3-[UIView(附加布局支持)\具有自动工程优化功能的UIU不允许DIFengineexists:+67 8 UIKit 0x0000000111A989B-[UIView(附加布局支持)\切换到布局引擎:][242 9 UIKit 0x000000011119ae6b-[UIWindow(UIConstraintBasedLayout)\切换到LayoutEngine:+81 10 UIKit 0x000000011119af99-[UIWindow(UIConstraintBasedLayout)\ u initializeLayoutEngine]+282 11 UIKit 0x000000011119b022-[UIWindow(UIConstraintBasedLayout)\如有必要,布局工程创建]+62 12 UIKit 0x000000011119 B2E3-[UIWindow(UIConstraintBasedLayout)updateConstraintsIfNeeded]+60 13 UIKit 0x00000001111aba22-[UIView(额外布局支持)\u updateConstraintsTengineLevel如果需要]+272 14 UIKit 0x000000011098259e-[UIView(层次结构)\u updateConstraintsAsNecessary和ApplyLayoutFromEngine]+159 15 UIKit 0x00000001109924cc-[UIView(CALayerDelegate)布局层的子层:+744 16夸脱核心0x000000010fc3259a-[CALayer布局子层]+146 17夸脱核心0x000000010fc26e70(如果需要)ZN2CA516层布局交易+366 18 QuartzCore 0x000000010fc26cee\u ZN2CA58层布局和显示(如果需要)PNS\u 11事务+24 19 QuartzCore 0x000000010fc1b475_ZN2CA7Context18提交交易PNS_11交易+277 20夸脱矿石0x000000010fc48c0a_ZN2CA11Transaction6Committeev+486 21夸脱芯0x000000010fc48efc_ZN2CA11Transaction14释放_螺纹EPV+224 22 libsystem_pthread.dylib 0x0000000112ff339c_pthread_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和执行回调的标准方法以及如何解决此错误


附言:我不想用AFNetowrking,你的事故日志上说

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

因此,您应该在
主线程上执行此任务(修改自动布局引擎),如

   dispatch_async(dispatch_get_main_queue(), ^{

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

});

希望这会有帮助:)

-(void)getresponse:(NSMutableDictionary*)response\u dictionary
中,检查您是否在主线程中。如果不是,那就是问题所在。您只能在主线程中更改UI。使用GCD(大量示例)说明如何在主线程中执行此操作。@Larme感谢您的回复。但是如何从后台线程导航到主线程呢?