Typescript React 如何永久存储对象
美好的一天,
我正在用 React 编写一个指南针应用程序,但遇到了一些问题。
我正在使用 DeviceOrientationEvent,如果我添加 EventListener,它会定向到设备航向,而不是绝对地球航向。
我的想法是,要显示校准按钮,用户必须将手机朝向北方(设备航向 === 绝对地球航向),然后按下按钮。
这里是一个代码示例:
calibrationButtonOnClick() //Method which is executed when pressing the calibration button
{
orientationHandler = await Motion.addListener("orientation", (event:any) => {orientationChange(event)});
//The orientationHandler object i want to store permanent.
}
如果按下按钮,我设置方向事件侦听器并获取指向北的 DeviceOrientationEvent。
我的问题:如果我重新启动应用程序,我必须重新校准应用程序。
我的想法:校准一次,然后永久存储“DeviceOrientationEvent”实例。重新启动后我可以加载并使用它。
你知道我如何存储对象实例吗?
我会将应用程序发布为 Android 应用程序
感谢您的帮助!
Good day,
I am coding a compass application in react and have some problems.
I am working with a DeviceOrientationEvent, if i add an EventListener it orientates to the device heading, not to the absolute earth heading.
My idea is, to display a calibration button, the user has to orientate his phone to north (deviceheading === absolute earth heading) and then press the button.
Here a code example:
calibrationButtonOnClick() //Method which is executed when pressing the calibration button
{
orientationHandler = await Motion.addListener("orientation", (event:any) => {orientationChange(event)});
//The orientationHandler object i want to store permanent.
}
If the button get pressed, i set the orientation event listener and get a DeviceOrientationEvent which points to north.
My problem: If i restart the application i have to calibrate the app new.
My idea: Calibrate it once and than store the "DeviceOrientationEvent" instance permanently. After restarting i can load and use it.
Have you some idea how i can store an object instance?
I´ll publish the application as android app
Thanks for help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种选择是利用本地存储来存储数据。
One option is to make use of local storage to store the data.