iOS应用程序的Xcode错误:必须仅从主线程调用[UI Application Delegate]

时间:2018-04-05 17:12:50

标签: ios objective-c

inline UnityAppController*  GetAppController()
{
    return (UnityAppController*)[UIApplication sharedApplication].delegate;
}

上面的行给出了错误:

  

[UI Application Delegate]必须仅从主线程调用

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

使用主线程:

夫特:

DispatchQueue.main.async {

  let appController = GetAppController()

}

目标-C:

dispatch_async(dispatch_get_main_queue(), ^{
  UnityAppController* appController = GetAppController();
});