本文介绍了在调试模式和正常模式之间反应本机不同的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常复杂的问题.所以我在 github 上为这个问题创建了一个新的 repo.所以你可以克隆它,看看有什么问题.

hi I have a really complicated problem. So I created a new repo for this problem at github. So you can clone it and see what the problem is.

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

我正在使用 https://github.com/public-transport/hafas-client 在这个项目中获取火车和火车站信息.

I am using https://github.com/public-transport/hafas-client in this project to get train and railway station informations.

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

请求在

node_modules/hafas-client/lib/request

问题是在调试模式下一切正常(摇动手机并启动远程 JS 调试),但是当我停止 JS 调试时,我收到错误PARSE".

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'.

所以我在 request.js 中查找并在调试模式下而不是在调试模式下注销请求和响应.

So i looked up in request.js and logged out request and response in debug mode and not in 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"
    }
}

响应调试模式

所有信息.一切正常.

请求不在调试模式

{
    "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"
    }
}

不在调试模式下响应

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

我已经比较了请求.在这里您可以看到两个请求之间的区别.https://www.diffnow.com/?report=pvuq7问题是 outDate、outTime 和校验和.有人可以帮我吗?

I have compared the requests. Here you can see the difference between the two request.https://www.diffnow.com/?report=pvuq7The problem is outDate, outTime and checksum. Somebody can help me?

推荐答案

问题是 Luxon 库 在 hafas-client 库中.你会看到你在 repo 中提供的代码在 iOS 和 android 上运行良好,只有启用了远程调试.为什么?

The problem is the usage of the Luxon library within hafas-client library. You will see that your code provided in the repo runs fine on iOS and on android only with remote debugging enabled. Why?

启用远程调试后,代码不会在您的手机中运行,而是在 Chrome 浏览器的 V8 引擎中运行.当远程调试被禁用时,代码会在你的手机上运行,​​而在 android 的情况下,它运行在 2014 年末的 JavaScriptCore (JSC) 引擎上,该引擎是使用自定义设置编译的,用于本机反应——这可能会产生不同的结果.

When remote debugging is enabled the code does not run in your phone but in the V8 engine of your chrome browser. 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.

正如 luxon 文档指出,支持android 上的 react native 是有限的.

As the luxon docs point out, support for react native on android is limited.

在 iOS 上,react native 使用操作系统提供的 JSC,其中还包括 intl 功能.android上的JSC没有int支持的原因是JSC是和apk捆绑在一起的,如果用intl支持编译会增加几MB的apk大小.

On iOS, react native uses the JSC available from the OS, which also includes intl features. 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.

通过一些自定义(分叉 hafas 客户端)并解决日期问题,我相信您应该能够解决这个问题.您也可以使用 this 但请注意,您可能会遇到其他类型的问题可能很难获得帮助(有一段时间,Expo client 曾经使用从这个 repo 编译的 JSC,但他们由于一些问题,不得不停止使用自定义构建).

With a bit of cutomizations (forking the hafas client) and working around the date problems, I believe you should be able to fix this. 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).

或者,您可以尝试使用 intl polyfill

Alternatively, you may try using intl polyfill

我是怎么知道的?在这里你会看到错误对象包含一堆额外的信息.当您记录错误时,您只是获得 description 字段,但是如果您记录 request 字段,您将看到它包含 "outDate":无效的日期时间".来了!

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". There it is!

这篇关于在调试模式和正常模式之间反应本机不同的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:52