public static int RegisterNotification(int id, DateTime fireDate, string body) { if (fireDate < UnbiasedTime.Instance.Now()) // fire date is in past { return(-1); } // notifications are disabled if (PreferencesFactory.GetInt(Constants.KeyNotificationsAllowed, 1) == 0) { return(-1); } #if UNITY_IPHONE NotificationCenter.RequestPermissions((result) => { PreferencesFactory.SetInt(Constants.KeyNotificationsAllowed, result.IsSucceeded ? 1 : 0); //Debug.Log("RequestPermissions callback: err: " + (result.HasError ? result.Error.Message : null) + "; success: " + result.IsSucceeded + "; failed: " + result.IsFailed); }); var content = new NotificationContent(); content.Body = body; content.Badge = 1; var dateComponents = new DateComponents() { Year = fireDate.Year, Month = fireDate.Month, Day = fireDate.Day, Hour = fireDate.Hour, Minute = fireDate.Minute, Second = fireDate.Second }; var trigger = new CalendarTrigger(dateComponents); var request = new NotificationRequest(id.ToString(), content, trigger); NotificationCenter.AddNotificationRequest(request, (result) => { //Debug.Log("AddNotificationRequest callback: err: " + (result.HasError ? result.Error.Message : null) + "; success: " + result.IsSucceeded + "; failed: " + result.IsFailed); }); #endif #if UNITY_ANDROID TimeSpan delay = fireDate - UnbiasedTime.Instance.Now(); AndroidNotificationBuilder builder = new AndroidNotificationBuilder(id, GameManager.Instance.GameName, body, (int)delay.TotalSeconds); AndroidNotificationManager.Instance.ScheduleLocalNotification(builder); #endif return(id); }