简体   繁体   English

在调试模式和正常模式之间响应本机不同的行为

[英]React native different behaviour between debug mode and normal mode

hi I have a really complicated problem. 嗨,我有一个非常复杂的问题。 So I created a new repo for this problem at github. 所以我在github上为这个问题创建了一个新的repo。 So you can clone it and see what the problem is. 所以你可以克隆它,看看问题是什么。

https://github.com/guitar9/hafas-client-example https://github.com/guitar9/hafas-client-example

I am using https://github.com/public-transport/hafas-client in this project to get train and railway station informations. 我在这个项目中使用https://github.com/public-transport/hafas-client获取火车和火车站的信息。

client.journeys(münchenHbf, münchenPassing)
.then((response)=>{
  console.log('===============response=====================');
  console.log(response);
  console.log('====================================');
})
.catch(console.error)

the request is in 请求在

node_modules/hafas-client/lib/request

Problem is in debug mode everything works fine (shake phone and start remote JS Debugging), but when i stop JS Debugging i get Error 'PARSE'. 问题是在调试模式下一切正常(摇动手机并启动远程JS调试),但当我停止JS调试时,我得到错误'PARSE'。

So i looked up in request.js and logged out request and response in debug mode and not in debug mode. 所以我在request.js中查找并在调试模式下注销请求和响应,而不是在调试模式下。

Request Debug Mode 请求调试模式

{
    "method": "post",
    "body": "{\"lang\":\"en\",\"svcReqL\":[{\"cfg\":{\"polyEnc\":\"GPA\"},\"meth\":\"TripSearch\",\"req\":{\"outDate\":\"20180614\",\"outTime\":\"174837\",\"ctxScr\":null,\"getPasslist\":false,\"maxChg\":5,\"minChgTime\":0,\"depLocL\":[{\"lid\":\"A=1@L=008000261@\"}],\"viaLocL\":null,\"arrLocL\":[{\"lid\":\"A=1@L=008004158@\"}],\"jnyFltrL\":[{\"type\":\"PROD\",\"mode\":\"INC\",\"value\":\"1023\"},{\"type\":\"META\",\"mode\":\"INC\",\"meta\":\"notBarrierfree\"}],\"getTariff\":false,\"outFrwd\":true,\"getPT\":true,\"getIV\":false,\"getPolyline\":false,\"numF\":5,\"trfReq\":{\"jnyCl\":2,\"tvlrProf\":[{\"type\":\"E\",\"redtnCard\":null}],\"cType\":\"PK\"}}}],\"client\":{\"id\":\"DB\",\"v\":\"16040000\",\"type\":\"IPH\",\"name\":\"DB Navigator\"},\"ext\":\"DB.R15.12.a\",\"ver\":\"1.16\",\"auth\":{\"type\":\"AID\",\"aid\":\"n91dB8Z77MLdoR0K\"}}",
    "headers": {
        "Content-Type": "application/json",
        "Accept": "application/json",
        "user-agent": "https://github.com/public-transport/hafas-client"
    },
    "query": {
        "checksum": "6af3b74db20e14c7f94012e3de55dce6"
    }
}

Response Debug Mode 响应调试模式

all informations. 所有信息。 everything okay. 一切都好。

Request not in debug mode 请求不在调试模式下

{
    "method": "post",
    "body": "{\"lang\":\"en\",\"svcReqL\":[{\"cfg\":{\"polyEnc\":\"GPA\"},\"meth\":\"TripSearch\",\"req\":{\"outDate\":\"Invalid DateTime\",\"outTime\":\"Invalid DateTime\",\"ctxScr\":null,\"getPasslist\":false,\"maxChg\":5,\"minChgTime\":0,\"depLocL\":[{\"lid\":\"A=1@L=008000261@\"}],\"viaLocL\":null,\"arrLocL\":[{\"lid\":\"A=1@L=008004158@\"}],\"jnyFltrL\":[{\"type\":\"PROD\",\"mode\":\"INC\",\"value\":\"1023\"},{\"type\":\"META\",\"mode\":\"INC\",\"meta\":\"notBarrierfree\"}],\"getTariff\":false,\"outFrwd\":true,\"getPT\":true,\"getIV\":false,\"getPolyline\":false,\"numF\":5,\"trfReq\":{\"jnyCl\":2,\"tvlrProf\":[{\"type\":\"E\",\"redtnCard\":null}],\"cType\":\"PK\"}}}],\"client\":{\"id\":\"DB\",\"v\":\"16040000\",\"type\":\"IPH\",\"name\":\"DB Navigator\"},\"ext\":\"DB.R15.12.a\",\"ver\":\"1.16\",\"auth\":{\"type\":\"AID\",\"aid\":\"n91dB8Z77MLdoR0K\"}}",
    "headers": {
        "Content-Type": "application/json",
        "Accept": "application/json",
        "user-agent": "https://github.com/public-transport/hafas-client"
    },
    "query": {
        "checksum": "0d8186da7b06f9cc094075a2a6e21b00"
    }
}

Response not in debug mode 响应不在调试模式下

{
    "ver": "1.16",
    "ext": "DB.R15.12.a",
    "lang": "eng",
    "id": "",
    "err": "PARSE",
    "svcResL": []
}

I have compared the requests. 我已经比较了这些要求。 Here you can see the difference between the two request. 在这里你可以看到两个请求之间的区别。 https://www.diffnow.com/?report=pvuq7 The problem is outDate, outTime and checksum. https://www.diffnow.com/?report=pvuq7问题是outDate,outTime和checksum。 Somebody can help me? 有人可以帮帮我吗?

The problem is the usage of the Luxon library within hafas-client library. 问题是的用法力信通库 hafas客户端库中。 You will see that your code provided in the repo runs fine on iOS and on android only with remote debugging enabled. 您将看到repo中提供的代码在iOS和Android上运行正常,只启用了远程调试。 Why? 为什么?

When remote debugging is enabled the code does not run in your phone but in the V8 engine of your chrome browser. 启用远程调试后,代码不会在手机中运行,而是在Chrome浏览器的V8引擎中运行。 When the remote debugging is disabled, code runs on your phone, where in case of android, it runs on a JavaScriptCore (JSC) engine from late 2014 that was compiled with custom setup for react native - that can, potentially, deliver different results. 当禁用远程调试时,代码会在您的手机上运行,​​在Android的情况下,它在2014年末运行的JavaScriptCore(JSC)引擎上运行,该引擎使用自定义设置进行编译,可能会产生不同的结果。

As the luxon docs point out , support for react native on android is limited. 正如luxon文档指出的那样 ,对android上的本机反应的支持是有限的。

On iOS, react native uses the JSC available from the OS, which also includes intl features. 在iOS上,react native使用OS提供的JSC,其中还包括intl功能。 The reason JSC on android does not have int support is that JSC is bundled together with the apk, and compiling it with intl support would increase the apk size by several MB. android上的JSC没有int支持的原因是JSC与apk捆绑在一起,并且使用intl支持编译它会使apk大小增加几MB。

With a bit of cutomizations (forking the hafas client) and working around the date problems, I believe you should be able to fix this. 通过一些cutomizations(分叉hafas客户端)和解决日期问题,我相信你应该能够解决这个问题。 You may also use this but beware that you may run into other sorts of issues that may be hard to get help with (for a while, the Expo client used to use the JSC compiled from this repo but they had to stop using the custom build because of some problems). 您也可以使用它,但要注意您可能会遇到其他可能难以获得帮助的问题(有一段时间, Expo客户端过去常常使用从此repo编译的JSC,但他们不得不停止使用自定义构建因为一些问题)。

Alternatively, you may try using intl polyfill 或者,您可以尝试使用intl polyfill

How did I find out? 我是怎么知道的? here you'll see that the error object contains a bunch of extra information. 在这里你会看到错误对象包含一堆额外的信息。 When you were logging the error, you were just getting the description field, but if you log the request field, you'll see that it contains "outDate": "Invalid DateTime" . 当您记录错误时,您只是获取description字段,但是如果您记录request字段,您将看到它包含"outDate": "Invalid DateTime" There it is! 它就是!

Author of hafas-client here. hafas-client作者在这里。 Posting as an answer for visibility and because I don't have the reputation to comment. 发布作为可见性的答案,因为我没有评论的声誉。

As I have documented in https://github.com/public-transport/hafas-client/issues/56#issuecomment-399915315 , I managed to use hafas-client@3.0.0-alpha.9 out-of-the-box in react-native, after I had added the node-libs-react-native shims . 正如我在https://github.com/public-transport/hafas-client/issues/56#issuecomment-399915315中记录的那样, 我设法使用了hafas-client@3.0.0-alpha.9 。在我添加了node-libs-react-native填充程序后,react-native中的框。 Please try this. 请试试这个。

There might of course be another issue related to luxon (as discussed in https://stackoverflow.com/a/51005700 ), but at least querying data without EPARSE errors or undecoded response payloads are not related to luxon and apparently solved. 当然也有可能是涉及到另一个问题, luxon (如在讨论https://stackoverflow.com/a/51005700 ),但没有起码查询数据EPARSE错误或者未解码的响应有效载荷,以相关luxon ,显然解决了。

暂无
暂无

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

相关问题 在调试模式和正常模式下反应原生不同的行为 react-native“:”0.60.4 - React native different behaviour between debug mode and normal mode react-native“: ”0.60.4 React Native,date.getTime()的结果在调试和正常模式下是不同的 - React Native, result of date.getTime () is different in debug and normal mode react-native-calendars npm 模块的 CalendarList 组件中的日历天在正常模式下似乎被禁用/变灰,但在调试模式下工作正常 - Calendar days in CalendarList component of react-native-calendars npm module seems disabled/grayed out in normal mode but works fine in debug mode JavaScript在调试模式下工作,但在正常模式下工作 - JavaScript works in debug mode but not working normal mode 为什么 React Native Android 应用程序在调试模式下运行速度很慢? - Why React Native Android app is running very slow on debug mode? 无需登录调试模式即可反应本机应用程序崩溃 - react native app crash without log in debug mode AsyncStorage 不匹配数据与钩子在调试模式下反应原生 - AsyncStorage mismatch data with hook react native in debug mode React Native的离线模式 - Offline mode in react native ThreeJS:纹理在调试中显示,但在正常模式下不显示 - ThreeJS: Texture shows up in debug, but not in normal mode 带有 javascript 调试的 Visual Studio 在直接运行和在调试模式下运行时显示不同的行为 - visual studio with javascript debugging showing different behaviour while running directly and by running in debug mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM