locked
HttpClient.GetAsync throw "APP Unexpectedly quit" in iOS. RRS feed

  • Question

  • User369256 posted

    Hi,

    I have this problem in my app.

    When I use HttpClient. GetAsync on OnStart Method of App throw "App Unexpectedly Quit" in iOS. I use the same method in other place and it works fine but in this method crash the app in iOS. In Android works fine too.

    This is my code:

            public async Task<Response> Get<T>(string endpoint, string prefixtToken,string Istrick, string accessToken = null)
                    {
                        try
                        {
                            var client = new HttpClient();
                            var autorizationToken = prefixtToken + accessToken;
                            if (accessToken != null || !string.IsNullOrEmpty(accessToken))
                                client.DefaultRequestHeaders.Add("Authorization", autorizationToken);
    
                            client.BaseAddress = new Uri(URLBASE);
                            var url = string.Format("{0}", endpoint);
                            var response = await client.GetAsync(url);
    
                            if (!response.IsSuccessStatusCode)
                            {
                                client.Dispose();
                                return new Response
                                {
                                    IsSuccess = false,
                                    Message = response.StatusCode.ToString(),
                                };
                            }
    
                            var result = await response.Content.ReadAsStringAsync();
                            var list = JsonConvert.DeserializeObject<T>(result);
    
                            client.Dispose();
                            return new Response
                            {
                                IsSuccess = true,
                                Message = "Ok",
                                Result = list,
                            };
                        }
                        catch (Exception ex)
                        {
    
                            return new Response
                            {
                                IsSuccess = false,
                                Message = ex.Message,
                            };
                        }
                    }
    

    This error isn't captured by try catch.

    Saturday, June 9, 2018 12:14 AM

Answers

  • User21936 posted

    @aixen85

    Using your code as a guide, I could not reproduce this issue.

    I might suggest that you check the iOS device logs for better information on why iOS is killing your app.

    Device console logs

    Visual Studio Windows: 1. Use the View->Other Windows->Device Log menu to launch the Device Log pane. 2. Choose the device in the Choose Device drop down list at the top of the pane.

    Visual Studio Mac: 1. Use the View->Pads->Device Log menu to launch the Device Log pane. 2. Choose the device in the Choose Device drop down list at the top of the pane.

    XCode: 1. Open Xcode with your device attached to your Mac. 2. Click the Window->Devices menu to open the Devices window. 3. Select your device from the list on the left and then click the small up arrow button on the lower left of the main pane. This will open the live console logs for the device.

    Simulator console logs

    1. Open the Console app on your Mac and select your simulator on the left

    If that does not reveal anything, can you provide a small test project that reproduce the issue, one that does not contain any sensitive, private data, and no intellectual property?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, June 9, 2018 1:56 AM

All replies

  • User21936 posted

    @aixen85

    Using your code as a guide, I could not reproduce this issue.

    I might suggest that you check the iOS device logs for better information on why iOS is killing your app.

    Device console logs

    Visual Studio Windows: 1. Use the View->Other Windows->Device Log menu to launch the Device Log pane. 2. Choose the device in the Choose Device drop down list at the top of the pane.

    Visual Studio Mac: 1. Use the View->Pads->Device Log menu to launch the Device Log pane. 2. Choose the device in the Choose Device drop down list at the top of the pane.

    XCode: 1. Open Xcode with your device attached to your Mac. 2. Click the Window->Devices menu to open the Devices window. 3. Select your device from the list on the left and then click the small up arrow button on the lower left of the main pane. This will open the live console logs for the device.

    Simulator console logs

    1. Open the Console app on your Mac and select your simulator on the left

    If that does not reveal anything, can you provide a small test project that reproduce the issue, one that does not contain any sensitive, private data, and no intellectual property?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, June 9, 2018 1:56 AM
  • User369256 posted

    I'm apologize for delay.

    Thanks

    Wednesday, June 13, 2018 12:41 AM
  • User369256 posted

    I'm apologize for delay.

    Thanks

    Wednesday, June 13, 2018 12:43 AM