Unity-Technologies / NotificationsSamples

Sample project for Unity Notifications
Other
282 stars 51 forks source link

i received the notice only when my app resume? #79

Open Jason-Zy opened 4 months ago

Jason-Zy commented 4 months ago

i add an notification in my test app , and then let the app run background, the notice should reach in two minutes. but it didnt, i wait it for more than 5 nimutes, when i reopen my app, it appeared, I've done multiple tests and the results are the same, why?

我在我的测试app中添加了一个通知,等待时间是两分钟,然后我把app 退到后台运行,超过两分钟之后仍然没有弹出通知,但是我重新打开app的时候,马上就收到了通知,我进行了多次测试,不同的时间,不同的内容,结果都是如此。下面是我的界面和代码: image

using System.Collections; using System.Collections.Generic; using Unity.Notifications; using UnityEngine; using UnityEngine.Playables; using UnityEngine.UI; using Unity.Notifications.Android; public class GameMain : MonoBehaviour { public InputField m_kPushTime; public InputField m_kPushTitle; public InputField m_kPushContent;

public Button m_kAddNotification;
// Start is called before the first frame update
void Start()
{
    m_kAddNotification.onClick.AddListener(OnAddNotificationClick);
    CreateChannel("channel_id_1","jason_channel","this is a good channel");
}

void OnAddNotificationClick()
{
    if (double.TryParse(m_kPushTime.text, out var time))
    {
        CreateNotification(m_kPushTitle.text,m_kPushContent.text,time,"channel_id_1");
    }
    else
    {
        Debug.LogError("时间参数获取错误");
    }
}

void CreateChannel(string channelId, string channelName,string channelDesc)
{
    var c = new AndroidNotificationChannel()
    {
        Id = channelId,
        Name = channelName,
        Importance = Importance.High,
        Description = channelDesc,
    };
    AndroidNotificationCenter.RegisterNotificationChannel(c);
}

void CreateNotification(string title,string content,double fireTime,string channelId)
{
    var notification = new AndroidNotification();
    notification.Title = title;
    notification.Text = content;
    notification.FireTime = System.DateTime.Now.AddMinutes(fireTime);

    AndroidNotificationCenter.SendNotification(notification, channelId);
}

}

joshuawilde commented 2 months ago

Did you ever find a solution @Jason-Zy? We also have this issue.