小编tbe*_*rgq的帖子

在 react-native 的主线程上运行 swift 代码

我正在尝试将 react-native 应用程序转换为 chromecast。chromecast GCKDeviceScanner 必须在主线程上运行。

反应本机页面说要在主线程上运行,您必须这样做:

- (dispatch_queue_t)methodQueue
{
  return dispatch_get_main_queue();
}
Run Code Online (Sandbox Code Playgroud)

I am not very familiar with swift or ios, so where do I put this code, and how do I use it? I have my method:

let filterCriteria = GCKFilterCriteria(forAvailableApplicationWithID: "myApp")
    
    let deviceScanner = GCKDeviceScanner(filterCriteria: filterCriteria)
    if let deviceScanner = deviceScanner {
      deviceScanner.addListener(self)
      deviceScanner.startScan()
      deviceScanner.passiveScan = true
    }
Run Code Online (Sandbox Code Playgroud)

Any idea on how I can run my code on the main thread?

ios swift react-native

3
推荐指数
1
解决办法
1601
查看次数

标签 统计

ios ×1

react-native ×1

swift ×1