Local notification in IOS app when app is background

want to send localnotification to my IOS app. App is checking time from my database when that time match to my mobile time it gives notification, but the problem that local notification works fine when my app is in foreground, when i close app local notification doesnt work any help will be appreciated

i have tried many things but couldnt succeed

here is my code i am running on App.cs

private async void CheckConnection()
{
var httpClient = new HttpClient();

    var json = await httpClient.GetStringAsync("http://192.168.10.55:56556/api/ShowAll");

    TimeSpan time = TimeSpan.FromSeconds(1);
    DateTime dateTime = DateTime.Today.Add(time);
    var admtPatients = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ContactDetail>>(json);
    ObservableCollection<ContactDetail> trends = new ObservableCollection<ContactDetail>(admtPatients);
    foreach (var item in trends)
    {
        if (item.TimeSchedule == DateTime.Now.ToString("hh:mm:ss"))
        {
            CrossLocalNotifications.Current.Show("title", "body");
        }
    }
    return;
}
protected override void OnStart()
{
    var seconds = TimeSpan.FromSeconds(1);

    Device.StartTimer(TimeSpan.FromSeconds(1), () =>
    {
        CheckConnection();
        return true;
    });

    // Handle when your app starts
}

protected override void OnSleep()
{
    base.OnSleep();
    var seconds = TimeSpan.FromSeconds(1);

    Device.StartTimer(TimeSpan.FromSeconds(1), () =>
    {
        CheckConnection();
        return true;
    });
}

protected override void OnResume()
{
    base.OnSleep();
    var seconds = TimeSpan.FromSeconds(1);

    Device.StartTimer(TimeSpan.FromSeconds(1), () =>
    {
        CheckConnection();
        return true;
    });
}
Tagged:

Answers

Sign In or Register to comment.