我终于找到了问题。
该问题是在 API 请求中发现的。我的请求需要 2 个时间戳参数:开始时间/结束时间
我总是使用浏览器调试应用程序并从 RN 项目启动 ios sim。
这次我尝试从 Xcode 运行项目并将 Scheme 编辑为 release 而不是 debug 。
当我从 Xcode 检查控制台时,我注意到我的开始时间时间戳被视为“NaN”.. 不是结束时间时间戳。
回到RN项目,回到浏览器控制台,时间戳没问题。
我做了一些随机更改,现在它工作正常。
这是我在解决问题之前所拥有的:
function formatDate(rawStamp) {
const now = new Date(rawStamp);
var convertToStr =
now.getFullYear() +
"-" +
("00" + (now.getMonth() + 1)).slice(-2) +
"-" +
("00" + now.getDate()).slice(-2) +
" " +
("00" + now.getHours()).slice(-2) +
":" +
("00" + now.getMinutes()).slice(-2) +
":" +
("00" + now.getSeconds()).slice(-2);
return convertToStr
}
const nowStr = formatDate(Date.now() - 7200000)
const gameStampMinusX = Date.parse(nowStr) - (300000)
const gameStampMinusXToStr = formatDate(gameStampMinusX)
这是解决问题的方法:
const nowStr = formatDate(Date.now() - 7200000)
const gameStampMinusX = Date.now() - 7200000 - 300000
const gameStampMinusXToStr = formatDate(gameStampMinusX)
I'm a newbie so I cannot explain this behavior, but seems that this little change makes Xcode recognize the timestamp, and proceed the the API request correctly.
If anyone can explain, feel free !