Network
Send HTTPS requests and monitor network type and connectivity changes. Check the corresponding CanIUse property before calling network APIs.
TT.Request(url, options, success, fail)
Sends an HTTPS request.
Signature
public static int Request(
string url,
TTRequest.InnerOptions options,
Action<TTRequest.Response> success,
Action<TTRequest.Response> fail)Parameters and return value
Parameter | Type | Description |
|
| HTTPS request URL that meets the platform request-domain requirements. |
|
| Whether to use TTNet. |
|
| Whether to use the cloud request path. |
|
| Success and failure callbacks. |
Return value |
| Task identifier for this request. |
Response
Field | Type | Description |
|
| Response headers. |
|
| HTTP status code. |
|
| Response body. |
|
| Failure message. |
|
| Whether the result came from prefetch. |
|
| Additional prefetch status. |
Example
int requestId = TT.Request(
"https://api.example.com/player",
new TTRequest.InnerOptions { UseTTNet = true, UseCloud = false },
response => Debug.Log($"HTTP {response.StatusCode}: {response.Data}"),
response => Debug.LogError($"Request failed: {response.ErrMsg}")
);Do not copy the JSSDK request parameter object into C#. The 1.1.6-Beta public C# signature accepts only the parameters above.
TT.GetNetWorkType(param)
Queries the current network type.
Signature
public static void GetNetWorkType(GetNetworkTypeParam param)Parameters and result
Field | Type | Description |
|
| Success callback. |
|
| Failure callback. |
NetWorkType can be NetworkWifi, Network2G, Network3G, Network4G, None, or Unknown.
Example
TT.GetNetWorkType(new GetNetworkTypeParam
{
Success = result => Debug.Log($"Network: {result.NetworkType}"),
Fail = error => Debug.LogError(error.ErrMsg)
});TT.OnNetworkStatusChange(callback)
Registers a listener for network status changes.
Signature
public static void OnNetworkStatusChange(OnNetworkStatusChangeCallback callback)The callback result contains bool IsConnected and NetWorkType NetworkType.
Example
OnNetworkStatusChangeCallback networkListener = result =>
Debug.Log($"Connected: {result.IsConnected}, Type: {result.NetworkType}");
TT.OnNetworkStatusChange(networkListener);TT.OffNetworkStatusChange(callback)
Removes a network status change listener.
Signature
public static void OffNetworkStatusChange(OnNetworkStatusChangeCallback callback)Example
TT.OffNetworkStatusChange(networkListener);TT.OnNetworkWeakChange(callback)
Registers a listener for weak network changes.
Signature
public static void OnNetworkWeakChange(OnNetworkWeakChangeCallback callback)The callback result contains bool WeakNet and NetWorkType NetworkType.
Example
OnNetworkWeakChangeCallback weakListener = result =>
Debug.Log($"Weak network: {result.WeakNet}, Type: {result.NetworkType}");
TT.OnNetworkWeakChange(weakListener);TT.OffNetworkWeakChange(callback)
Removes a weak network change listener.
Signature
public static void OffNetworkWeakChange(OnNetworkWeakChangeCallback callback)Example
TT.OffNetworkWeakChange(weakListener);