修正使用ios17sdk,在ios14+上crash的问题

This commit is contained in:
CounterFire2023 2023-10-17 11:46:14 +08:00
parent 324608d49a
commit 93f084fada

View File

@ -38,6 +38,7 @@
#include <functional>
#include <algorithm>
#include <sstream>
#include <locale>
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
#include "cocos/scripting/js-bindings/manual/jsb_conversions.hpp"
#include "cocos/network/HttpClient.h"
@ -350,11 +351,17 @@ void XMLHttpRequest::setReadyState(ReadyState readyState)
}
}
std::string to_lower(std::string s) {
for(char &c : s)
c = tolower(c);
return s;
}
void XMLHttpRequest::getHeader(const std::string& header)
{
// check for colon.
size_t found_header_field = header.find_first_of(":");
// size_t found_header_field = header.find_first_of(":");
unsigned long found_header_field = header.find(":");
if (found_header_field != std::string::npos)
{
// Found a header field.
@ -375,9 +382,10 @@ void XMLHttpRequest::getHeader(const std::string& header)
}
// Transform field name to lower case as they are case-insensitive
std::transform(http_field.begin(), http_field.end(), http_field.begin(), ::tolower);
std::string lower_http_field = to_lower(http_field);
// std::transform(http_field.begin(), http_field.end(), http_field.begin(), ::tolower);
_httpHeader[http_field] = http_value;
_httpHeader[lower_http_field] = http_value;
}
else
@ -1042,7 +1050,7 @@ static bool XMLHttpRequest_setTimeout(se::State& s)
unsigned long timeoutInMilliseconds = 0;
bool ok = seval_to_ulong(args[0], &timeoutInMilliseconds);
SE_PRECONDITION2(ok, false, "args[0] isn't a number");
if (timeoutInMilliseconds < 50)
if (timeoutInMilliseconds < 50 && timeoutInMilliseconds != 0)
{
SE_LOGE("The timeout value (%lu ms) is too small, please note that timeout unit is milliseconds!", timeoutInMilliseconds);
}
@ -1111,6 +1119,14 @@ static bool XMLHttpRequest_setResponseType(se::State& s)
{
xhr->setResponseType(XMLHttpRequest::ResponseType::BLOB);
}
else if (type == "ms-stream")
{
xhr->setResponseType(XMLHttpRequest::ResponseType::BLOB);
}
else if (type == "moz-chunked-arraybuffer")
{
xhr->setResponseType(XMLHttpRequest::ResponseType::BLOB);
}
else
{
SE_PRECONDITION2(false, false, "The response type isn't supported!");