universal-tools / UTNotificationsFeedback

7 stars 0 forks source link

Scheduled Notification not working #102

Closed lafarcito closed 5 years ago

lafarcito commented 5 years ago

I get this error when i try to play notification scheduled.

03-18 10:38:16.515 31799-31799/com.AAA.BBB E/universal.tools.notifications.Manager: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference

Local notification work fine but cant schedule

yuriy-universal-ivanov commented 5 years ago

Hi @lafarcito ,

Please see https://forum.unity.com/threads/released-utnotifications-professional-cross-platform-push-notifications-and-more.333045/page-16#post-4331062.

Best regards, Yuriy, Universal Tools team.

lafarcito commented 5 years ago

My Script with custom class for schedule notification

public enum NOTIFICATION_ID { DailyNotification = 0, WeekNotification = 1, Week2Notification = 2, Week3Notification = 3, MonthNotification = 4}

[System.Serializable] public class CustomNotification { [SerializeField] NOTIFICATION_ID id; public NOTIFICATION_ID Id { get { return id; } } [SerializeField] int triggerTime; public int TriggerTime { get { return triggerTime; } } [SerializeField] string title; public string Title { get { return title; } } string message; public string Message { get { return message; } } }

public class NotificationManager : MonoBehaviour { private static NotificationManager instance; [SerializeField] CustomNotification[] notification;

private void Awake()
{
    if (instance == null)
    {
        instance = this;
    }else if (instance != this)
    {
        Destroy(gameObject);
        return;
    }
    DontDestroyOnLoad(gameObject);
}
// Start is called before the first frame update
void Start()
{
    UTNotifications.Manager.Instance.Initialize(false);
    UTNotifications.Manager.Instance.SetNotificationsEnabled(true); // I have try enabling this but nothing happen
    UTNotifications.Manager.Instance.PostLocalNotification("Title", "Hello", 100);

    for (int i = 0; i < notification.Length; i++)
    {
        UTNotifications.Manager.Instance.ScheduleNotification(notification[i].TriggerTime, notification[i].Title, notification[i].Message,(int) notification[i].Id);
    }
}

}

Target device MIA1 Oreo

yuriy-universal-ivanov commented 5 years ago

Thanks, most likely either notification[i].Title or notification[i].Message (or both) is null. I suspect Message, as string message; is missing [SerializeField]

lafarcito commented 5 years ago

Nice! Thank you!