Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.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 在Swift 4.2中获取现有Objective-C代码的运行时错误_Ios_Objective C - Fatal编程技术网

Ios 在Swift 4.2中获取现有Objective-C代码的运行时错误

Ios 在Swift 4.2中获取现有Objective-C代码的运行时错误,ios,objective-c,Ios,Objective C,这就是错误: -[UIApplication statusBarOrientation]只能从主线程使用 StatusBaroOrientation在我的代码中有两个地方使用 这个在Objective-C.m文件中^^ 请提供任何线索或解决此问题。谢谢 问题不太可能来自1;错误可能来自您从主线程以外的线程读取statusBarOrientation成员 以下是从主线程读取StatusBaroOrientation的方式: dispatch_async(dispatch_get_main_queu

这就是错误:

-[UIApplication statusBarOrientation]只能从主线程使用

StatusBaroOrientation在我的代码中有两个地方使用

这个在Objective-C.m文件中^^


请提供任何线索或解决此问题。谢谢

问题不太可能来自1;错误可能来自您从主线程以外的线程读取statusBarOrientation成员

以下是从主线程读取StatusBaroOrientation的方式:

dispatch_async(dispatch_get_main_queue(), ^(void){
    // Now, we are in the context of the main (GUI) thread. You can perform any GUI updates here.
    self.frame = [[[UIApplication sharedApplication] delegate] window].bounds;
    UIInterfaceOrientation orientation = UIApplication.sharedApplication.statusBarOrientation;
    // Put any other code that makes use of the "orientation" variable inside here

});

从现在开始,,这完全取决于您想对方向变量执行什么操作。

发布您在中使用它们的上下文您是否尝试过执行错误指示的操作?UIInterfaceOrientation orientation=UIApplication.sharedApplication.statusBarOrientation未在主线程上调用,必须调用。您有线程冲突-statusBarOrientation只能在主线程的上下文中调用。你需要做一些挖掘工作,找出这个方法是如何被调用的,如果可以的话,确定它被调用的线程,并进行更改,以便调用在主线程中结束。要在主线程中调用方法,请使用Grand Central Dispatch GCD,google up bruv。
UIInterfaceOrientation orientation = UIApplication.sharedApplication.statusBarOrientation;
dispatch_async(dispatch_get_main_queue(), ^(void){
    // Now, we are in the context of the main (GUI) thread. You can perform any GUI updates here.
    self.frame = [[[UIApplication sharedApplication] delegate] window].bounds;
    UIInterfaceOrientation orientation = UIApplication.sharedApplication.statusBarOrientation;
    // Put any other code that makes use of the "orientation" variable inside here

});