Toast make disappear very fast in iOS devices.

Bhuwan 616 Reputation points
2024-03-11T17:12:04.65+00:00

In Android below code is working fine but in iOS it's disappear very fast means come and then directly close within milli second

iOS version 17.2 in .NET 8.0
XCode version - 15.3
CommunityToolkit.Maui Version - 7.0.1


public class ToastMessageFunction

{
    /// <summary>`

    /// ToastErrorMessage`

    /// </summary>`

    /// <returns></returns>`

    /// <param name="Message"></param>`

    /// <param name="toastDuration"></param>`

    /// <param name="textSize"></param>`

    public static Toast ToastErrorMessage(string Message, ToastDuration toastDuration, int textSize)

    {

        return (Toast)Toast.Make(Message, duration: toastDuration, textSize: textSize);

    }

    /// <summary>

    /// ToastSucessMessage

    /// </summary>

    /// <returns></returns>

   /// <param name="Message"></param>

    /// <param name="toastDuration"></param>

    /// <param name="textSize"></param>

    public static Toast ToastSucessMessage(string Message, ToastDuration toastDuration, int textSize)`

    {

        return (Toast)Toast.Make(Message, duration: toastDuration, textSize: textSize);

    }

    /// <summary>

    /// ToastWarningMessage

   /// </summary>
   /// <returns></returns>

    /// <param name="Message"></param>

    /// <param name="toastDuration"></param>

    /// <param name="textSize"></param>

   public static Toast ToastWarningMessage(string Message, ToastDuration toastDuration, int textSize)

    {

       return (Toast)Toast.Make(Message, duration: toastDuration, textSize: textSize);

    }

used like this

await (Functions.ToastMessageFunction.ToastErrorMessage(message, CommunityToolkit.Maui.Core.ToastDuration.Short, 14)).Show(cancellationTokenSource.Token);
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,988 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AEH-2740 0 Reputation points
    2024-05-13T12:50:46.4966667+00:00

    I had the same issue with iOS. I've managed to find a workaround for now, which is to add a short delay before showing the toast.

    So for you it would be something like this:

    #if IOS
      await Task.Delay(250);  
    #endif
    
    await (Functions.ToastMessageFunction.ToastErrorMessage(message, CommunityToolkit.Maui.Core.ToastDuration.Short, 14)).Show(cancellationTokenSource.Token);
    
    0 comments No comments