How can I make my app send out notifications when it's loaded but not running in the foreground?

后端 未结 2 723
执笔经年
执笔经年 2021-02-06 00:51

I have an app that I use sometimes. I must have left it there in the background before I slept. When I woke up I saw this notification on my screen.

Does anyo

2条回答
  •  执笔经年
    2021-02-06 00:52

    You can use Notifications to achieve this function. From document Local notifications in Xamarin.Forms,we will find:

    Local notifications are alerts sent by applications installed on a mobile device. Local notifications are often used for features such as:

    • List item
    • Calendar events
    • Reminders

    Location-based triggers Each platform handles the creation, display, and consumption of local notifications differently.

    You can defines a cross-platform API that the application can use to interact with notifications.

      public interface INotificationManager
    {
        event EventHandler NotificationReceived;
    
        void Initialize();
    
        int ScheduleNotification(string title, string message);
    
        void ReceiveNotification(string title, string message);
    }
    

    For more details, you can check above document, and this link also contains a sample about Notifications.It should be helpful for you.

    Of course, if you want your app send notification when app is in background, you can use background-tasks.

    For more details,you can check:

    https://xamarinhelp.com/xamarin-background-tasks/

    https://docs.microsoft.com/zh-cn/xamarin/ios/app-fundamentals/backgrounding/

    https://docs.microsoft.com/en-ie/xamarin/android/app-fundamentals/services/creating-a-service/

提交回复
热议问题