Hi everyone,
I am developing a cross platform mobile app, whenever I sent my app to release on Apple's App Store, my app is rejected because of connection problem. I detect the problem and it is caused by my rest api. To connect my server, there are fields that take server ip and port number, and I use these inputs to create query. After click login button, query is generated and system is tried to connect to the server, but main problem here is that, first connection attempt is not happened. When I run both server and client sides in debug mode, my request do not recieve to the server side. This happens only if app is installed to new device (if app is not installed before that device). If I relaunch app after closing it, connection is established and everything works as expected.
I use try catch block to get what is the error message but the problem never happen on my device and iphone/android emulators. Here is the codes both client and server side.
Client:
public async Task getData()
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/json");DataModel model = new DataModel();
string addr = "http://" + txtServer.Text + ":" + txtPort.Text + "/Service/api/test/getData";
var response = await client.PostAsync(addr, new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json")); var result = await response.Content.ReadAsStringAsync(); var res = JsonConvert.DeserializeObject<ResultStruct>(result); return JsonConvert.DeserializeObject<DataModel> (res.Data.ToString()); }
Server:
[HttpPost]
[Route("getData")]
public ResultStruct getData()
{
ResultStruct result = new ResultStruct();
result.Result = true;
try
{
result.Data = getDataFromDB();
result.Message = "Success";
}
catch (Exception ex)
{
result.Result = false;
result.Message = ex.Message;
}
return result;
}