菜鸟教程小白 发表于 2022-12-13 02:36:42

ios - 如何将大量整数从 ObjC 传递给 JS?


                                            <p><p>目前我们将数据从 ObjC 传递给 JS 作为巨大的字符串,其中所有整数都转换为字符串并以逗号分隔。有没有更好的办法?我在这里浏览了许多我认为可能相关的问题,以及 <a href="https://stackoverflow.com/questions/21616641/javascriptcore-external-arrays" rel="noreferrer noopener nofollow">here</a>有人提到:</p>

<blockquote>
<p>The build of JavaScriptCore that comes with iOS 7 does have typed arrays, but unfortunately the public API doesn&#39;t expose them so you can&#39;t touch their data from native.</p>
</blockquote>

<p>我想知道这是真的还是有其他方法?也许以数组作为参数调用 JS 函数,该参数将转换为数组参数?或者它可以被翻译成很多参数,然后使用 <code>Fucntion.arguments</code>。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>如果您使用 JSContext ObjC API,您可以简单地将 NSNumber 对象的 NSArray 传递给 JavaScriptCore,它会自动将其转换为 JavaScript 数字数组。虽然到目前为止不如类型化数组高效,但它应该比对字符串进行切片更好。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何将大量整数从 ObjC 传递给 JS?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/26378743/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/26378743/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何将大量整数从 ObjC 传递给 JS?