<i id='mWfRM'><tr id='mWfRM'><dt id='mWfRM'><q id='mWfRM'><span id='mWfRM'><b id='mWfRM'><form id='mWfRM'><ins id='mWfRM'></ins><ul id='mWfRM'></ul><sub id='mWfRM'></sub></form><legend id='mWfRM'></legend><bdo id='mWfRM'><pre id='mWfRM'><center id='mWfRM'></center></pre></bdo></b><th id='mWfRM'></th></span></q></dt></tr></i><div id='mWfRM'><tfoot id='mWfRM'></tfoot><dl id='mWfRM'><fieldset id='mWfRM'></fieldset></dl></div>
    • <bdo id='mWfRM'></bdo><ul id='mWfRM'></ul>

    <small id='mWfRM'></small><noframes id='mWfRM'>

      <tfoot id='mWfRM'></tfoot>
    1. <legend id='mWfRM'><style id='mWfRM'><dir id='mWfRM'><q id='mWfRM'></q></dir></style></legend>

      区别需要MainQueueSetup 和dispatch_get_main_queue?

      Difference requiresMainQueueSetup and dispatch_get_main_queue?(区别需要MainQueueSetup 和dispatch_get_main_queue?)
        <bdo id='vrw8f'></bdo><ul id='vrw8f'></ul>

        <small id='vrw8f'></small><noframes id='vrw8f'>

          <tfoot id='vrw8f'></tfoot>

              <tbody id='vrw8f'></tbody>
          • <i id='vrw8f'><tr id='vrw8f'><dt id='vrw8f'><q id='vrw8f'><span id='vrw8f'><b id='vrw8f'><form id='vrw8f'><ins id='vrw8f'></ins><ul id='vrw8f'></ul><sub id='vrw8f'></sub></form><legend id='vrw8f'></legend><bdo id='vrw8f'><pre id='vrw8f'><center id='vrw8f'></center></pre></bdo></b><th id='vrw8f'></th></span></q></dt></tr></i><div id='vrw8f'><tfoot id='vrw8f'></tfoot><dl id='vrw8f'><fieldset id='vrw8f'></fieldset></dl></div>
            1. <legend id='vrw8f'><style id='vrw8f'><dir id='vrw8f'><q id='vrw8f'></q></dir></style></legend>
                本文介绍了区别需要MainQueueSetup 和dispatch_get_main_queue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试了解如何为 iOS 创建 react-native 模块,并且出现了一个方面

                I am trying to learn about creating react-native modules for iOS and there is one aspect that came up

                关于线程的官方文档提到了这一点代码块及其变体

                Official documentation on threading mentions this block of code alongside its variations

                - (dispatch_queue_t)methodQueue
                {
                  return dispatch_get_main_queue();
                }
                

                我在第三方库中看到了很多另一种无证和平,就是这样

                There is another undocumented peace I saw a lot in the third party libraries which is this

                + (BOOL)requiresMainQueueSetup
                {
                    return NO;
                }
                

                对我来说,这些看起来有点相似但又不同,因此我想对以下问题进行解释

                To me, these look kinda similar yet different, hence I wanted to ask for an explanation of following questions

                1. 什么时候应该将dispatch_get_main_queue添加到模块中,如果省略会发生什么?

                1. When should dispatch_get_main_queue be added to the module and what happens if it is omitted?

                什么时候应该将requiresMainQueueSetup添加到模块中,如果省略会发生什么?

                When should requiresMainQueueSetup be added to the module and what happens if it is omitted?

                dispatch_get_main_queuerequiresMainQueueSetup 是否可以一起使用,如果可以,为什么以及何时?

                Can dispatch_get_main_queue and requiresMainQueueSetup be used together, if so why and when?

                requiresMainQueueSetup返回YESNO有什么区别?

                推荐答案

                1. 每当您在辅助线程上处理会影响主线程的事件时,您都需要 dispatch_get_main_queue().通常这涉及 UI 更改.如果你正在创建一个不涉及原生渲染的 react-native 模块,你可能不需要主队列.应该在辅助线程上调用异步内容,您可以在此处实现 dispatch_get_main_queue() 以确保在异步操作完成时更新 UI.

                1. You need dispatch_get_main_queue() whenever you are processing events on a secondary thread which will influence the main thread. Typically this involves UI changes. If you are creating a react-native module which does not involve native rendering you will probably not need the main queue. Async stuff should be invoked on a secondary thread, and this is where you would implement dispatch_get_main_queue() to make sure you UI gets updated when you async actions are completed.

                几周前我在 SO 上问了同样的问题,但没有成功,经过一些研究,我现在知道这与第 1 号项目符号有关.React-native 期望你实现这个方法(无论如何都不与 iOS 相关),您需要返回 YES 才能进行原生 iOS 渲染.这将确保您的本机模块在与 UI 交互相关的主线程上运行.您不希望应用程序在执行繁重的处理时冻结您的 UI.

                I asked this same question on SO a few weeks ago without success, and after some research I now know this is related to bullet number 1. React-native expects you to implement this method (is not in any way related to iOS), and you will need return YES in you want to do native iOS rendering. This will ensure that your native module is run on the main thread which is relevant in case of UI interactions. You don't want the application to freeze your UI in case of heavy duty processing.

                如果你不提供 requiresMainQueueSetup(),react-native 会在你面前抛出一个警告,但此时会将其设置为 YES.此默认值将在即将发布的版本中更改为 NO.因此,回答您的问题:它们可以一起使用,但并非每种组合都有意义.同样在这种情况下,如果您没有创建新的原生 iOS UI 组件,您可能不需要通过 dispatch_get_main_queue() 访问主线程.react-native 桥将确保本地事件和方法始终从 iOS 传递到 JS,反之亦然,无论它们在哪个线程上运行.

                If you do not provide requiresMainQueueSetup() react-native will throw a warning in your face, but will set it to YES at this point. This default value will change in an upcoming release to NO. So to answer your question: they can be used together, but not every combination makes sense. Also in this case, if you are not creating a new native iOS UI component you will probably not need to access the main thread through dispatch_get_main_queue(). The react-native bridge will ensure that native events and methods are always communicated from iOS to JS and visa versa, regardless of which thread they are running on.

                这已在前面的项目符号中解决

                This has been addressed in the previous bullets

                一些额外的信息只是为了确保一切都清楚.总结一下: requiresMainQueueSetup() 与 iOS 无关,仅由 react-native 创建以了解您的原生模块的意图(UI 或其他).dispatch_get_main_queue() 与 react-native 无关,只与你的原生代码相关.它基本上是辅助线程的回调,以通知主线程一些异步操作已完成.

                Some additional information just to make sure everything is clear. To summarise: requiresMainQueueSetup() has nothing to do with iOS, and is only created by react-native to know what the intentions of your native module are (UI or other). dispatch_get_main_queue() has nothing to do with react-native and is only relevant to your native code. It is basically a callback for secondary threads to inform the main thread that some async actions are completed.

                这篇关于区别需要MainQueueSetup 和dispatch_get_main_queue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                what#39;s property copy means in Cocoa#39;s Framework?(like UITabBar#39;s items property)(Cocoa 框架中的属性副本是什么意思?(如 UITabBar 的 items 属性))
                Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)
                Automatically copy property values from one object to another of a different type but the same protocol (Objective-C)(自动将属性值从一个对象复制到另一个类型不同但协议相同的对象 (Objective-C))
                Copy text to clipboard with iOS(使用 iOS 将文本复制到剪贴板)
                How to copy text to clipboard/pasteboard with Swift(如何使用 Swift 将文本复制到剪贴板/粘贴板)
                How to show the progress of copying a large file in iOS?(如何在iOS中显示复制大文件的进度?)
                  <tbody id='SLvPJ'></tbody>

              • <tfoot id='SLvPJ'></tfoot>
                <legend id='SLvPJ'><style id='SLvPJ'><dir id='SLvPJ'><q id='SLvPJ'></q></dir></style></legend>
                  <bdo id='SLvPJ'></bdo><ul id='SLvPJ'></ul>

                  <small id='SLvPJ'></small><noframes id='SLvPJ'>

                    <i id='SLvPJ'><tr id='SLvPJ'><dt id='SLvPJ'><q id='SLvPJ'><span id='SLvPJ'><b id='SLvPJ'><form id='SLvPJ'><ins id='SLvPJ'></ins><ul id='SLvPJ'></ul><sub id='SLvPJ'></sub></form><legend id='SLvPJ'></legend><bdo id='SLvPJ'><pre id='SLvPJ'><center id='SLvPJ'></center></pre></bdo></b><th id='SLvPJ'></th></span></q></dt></tr></i><div id='SLvPJ'><tfoot id='SLvPJ'></tfoot><dl id='SLvPJ'><fieldset id='SLvPJ'></fieldset></dl></div>