简体   繁体   English

Xamarin.ios 不适用于真正的 iOS 设备,但它适用于模拟器

[英]Xamarin.ios does NOT work on real iOS device but it works on Simulator

I build a mobile App.我构建了一个移动应用程序。 This App is working really well on iOS simulator, Android emulator and Android real device.此应用程序在 iOS 模拟器、Android 模拟器和 Android 真实设备上运行良好。 But When I published it on TestFlight and install on a real iOS device then this app does not work.但是当我在 TestFlight 上发布它并安装在真正的 iOS 设备上时,这个应用程序无法运行。 I don't get any error.我没有收到任何错误。 My spinner(activator indicator) is running forever and I cannot get any response from HttpResponse.我的微调器(激活器指示器)一直在运行,我无法从 HttpResponse 获得任何响应。 I built this app with Web service.我用Web 服务构建了这个应用程序。 Therefore I'm using http://46.221..... url to post or get request.因此,我正在使用http://46.221..... url 来发布或获取请求。 I thought that iOS does not support http request because of security.由于安全原因,我认为iOS不支持http请求。 But if it's true then Why this app is running on simulator very well?但如果这是真的那么为什么这个应用程序在模拟器上运行得很好? I couldn't find any solution.我找不到任何解决方案。 Here is my part of codes:这是我的部分代码:

public async Task<BSUser> ValidateUser(string userName, string password)
    {
        string url = Xamarin.Essentials.Preferences.Get(Constants.URL_KEY, "") + "/api/Validateuser";
        HttpClient _Client = new HttpClient();

        var data = new Dictionary<string, string>
        {
          {"userName", userName},
          {"password", password}
        };

        string jsonData = JsonConvert.SerializeObject(data);
        HttpContent content = new StringContent(jsonData, Encoding.UTF8, "application/json");

        try
        {
            HttpResponseMessage httpResponse = await _Client.PostAsync(url, content);
            if (httpResponse.IsSuccessStatusCode)
            {
                var responseData = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
                var result = JsonConvert.DeserializeObject(responseData).ToString();
                UserInfo userInfo = JsonConvert.DeserializeObject<UserInfo>(result);

                BSUser value = new BSUser();
                value.UserName = userInfo.userCode;

                return value;
            }
            else
            {
                return null;
            }
        }
        catch (SystemException)
        {
            return null;
        }
    }

enter image description here在此处输入图像描述

I found the problem of my project.我发现了我项目的问题。 It's not related on HTTPS-HTTP or security situation.它与 HTTPS-HTTP 或安全情况无关。 It's so absurd and illogical but it's the real problem.这是如此荒谬和不合逻辑,但这是真正的问题。 My app works on any iOS simulator well enough however, Minimum version of simulator is iPhone-8 in Visual Studio.我的应用程序在任何 iOS 模拟器上运行得很好,但是,模拟器的最低版本是 Visual Studio 中的iPhone-8 But When I installed my app on real devices of iPhone-6 I got Newtonsoft.Json.JsonSerializationException error.但是当我在iPhone-6 的真实设备上安装我的应用程序时,出现了Newtonsoft.Json.JsonSerializationException错误。 But My HttpResponse returned 200OK and I see all values which comes from my service as a json. I think there some difference between old ve new versions of iPhones to convert Json Serialization.但是我的 HttpResponse 返回了 200OK ,我看到来自我的服务的所有值都是 json。我认为旧版本和新版本的 iPhone 转换 Json 序列化之间存在一些差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM