简体   繁体   English

如何对Android和iOS的本机kontaktio进行单反应

[英]how to single react native kontaktio for android and ios

How do I make a single component (say MainContent.js) that branches off according to the Platform to start scanning for beacons, with the kontaktio ios api, on an iphone, but with the kontaktio android api on an android phone? 如何使用Platform上的kontaktio ios api,但使用android手机上的kontaktio android api,使单个组件(例如MainContent.js)根据Platform分支以开始扫描信标?

The scanning is configured and callbacks are set up, in componentDidMount(), and also the scanning itself is started in componentDidMount(). 在componentDidMount()中配置了扫描并设置了回调,并且扫描本身也在componentDidMount()中启动。

But the ios kontaktio api uses NativeEmitter and has a very different api from the android kontaktio api which uses DeviceEmitter and has very different events, methods, and structures, (for example using connect() instead of init()). 但是ios kontaktio api使用NativeEmitter并具有与android kontaktio api完全不同的api,后者使用DeviceEmitter并具有非常不同的事件,方法和结构(例如,使用connect()代替init())。

I cannot do this in one code file, because I need to import different things and set different constants for each platform. 我无法在一个代码文件中执行此操作,因为我需要导入不同的内容并为每个平台设置不同的常量。 But the results are the same. 但是结果是一样的。 I identify a beacon nearby and set some state. 我在附近找到一个信标并设置了一些状态。 (for example through Redux). (例如通过Redux)。

There's probably a simple way to do it, and this is most likely a stupid question, but somehow I cannot think of a way to do this since the components are not visual and there is no "render". 可能有一个简单的方法可以解决这个问题,这很可能是一个愚蠢的问题,但是由于组件不可见并且没有“渲染”,所以我不知道该怎么做。

OK. 好。 From these answers here: Can I require a module specifically for iOS in React Native? 从这里的这些答案中: 我可以在React Native中要求一个专门用于iOS的模块吗? I learned to make an AppMain.ios.js and an AppMain.android.js and automatically react native chooses the correct one. 我学会了制作AppMain.ios.js和AppMain.android.js并自动做出反应,以选择本机。

I had to uninstall the latest app on my device, and then did a gradlew clean in the android directory, and then ran on device as usual and everythings ok. 我必须卸载设备上的最新应用程序,然后在android目录中进行gradlew clean ,然后像往常一样在设备上运行,一切正常。 Similarly for the iphone. 对于iPhone同样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM