// Call by main game OnApplicationPause public void ScheduleReturnBackToGameNotification() { #if UNITY_ANDROID NotificationParams notification = new NotificationParams { Id = NotificationIdHandler.GetNotificationId(), Ticker = "Ticker", Sound = true, Vibrate = true, Light = true, LargeIcon = "app_icon", SmallIcon = NotificationIcon.Heart, SmallIconColor = new Color(0, 0.5f, 0), CallbackData = "ScheduleReturnBackToGameNotification", // name of method Delay = TimeSpan.FromSeconds(inactiveLatelyNotificationDelayInSeconds), Title = androidAppTitle, Message = inactiveLatelyMessage }; NotificationManager.SendCustom(notification); #elif UNITY_IOS LocalNotification notification = new LocalNotification { applicationIconBadgeNumber = 1, alertBody = inactiveLatelyMessage, fireDate = DateTime.Now.AddSeconds(inactiveLatelyNotificationDelayInSeconds), soundName = LocalNotification.defaultSoundName }; NotificationServices.ScheduleLocalNotification(notification); #endif }
//-------------------------------------- // INITIALIZE //-------------------------------------- protected override void Awake() { base.Awake(); #if UNITY_IOS && UNITY_5 if (UnityEngine.iOS.NotificationServices.localNotificationCount > 0) { UnityEngine.iOS.LocalNotification n = UnityEngine.iOS.NotificationServices.localNotifications[0]; ISN_LocalNotification notif = new ISN_LocalNotification(DateTime.Now, n.alertBody, true); int id = 0; if (n.userInfo.Contains("AlarmKey")) { id = System.Convert.ToInt32(n.userInfo["AlarmKey"]); } if (n.userInfo.Contains("data")) { notif.SetData(System.Convert.ToString(n.userInfo["data"])); } notif.SetId(id); _LaunchNotification = notif; } #endif }
void OnApplicationQuit() { UnityEngine.iOS.LocalNotification notif = new UnityEngine.iOS.LocalNotification(); notif.fireDate = DateTime.Now.AddDays(sendNotif); notif.alertBody = "Come back and play some 2D Basketball!"; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notif); }
void OnApplicationPause(bool pauseStatus) { #if UNITY_ANDROID if (pauseStatus) { NotificationManager.SendWithAppIcon(TimeSpan.FromSeconds(Constants.PUSH_NOTIFICATIONS_REPEAT_TIME), Constants.PUSH_NOTIFICATIONS_TITLE, Constants.PUSH_NOTIFICATIONS_BODY, new Color(0, 0.6f, 1), NotificationIcon.Message); } else { NotificationManager.CancelAll(); } #elif UNITY_IOS if (pauseStatus) { var notification = new UnityEngine.iOS.LocalNotification { fireDate = DateTime.Now.AddSeconds(Constants.PUSH_NOTIFICATIONS_REPEAT_TIME), alertAction = Constants.PUSH_NOTIFICATIONS_TITLE, alertBody = Constants.PUSH_NOTIFICATIONS_BODY }; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notification); } else { UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications(); } #endif }
public void AddNotification(float _delayTime, string _content) { if (!Enabled) { return; } Debug.Log("Add Local Notify " + "delay: " + (_delayTime).ToString() + ". content: " + _content); #if UNITY_IPHONE UnityEngine.iOS.LocalNotification notify = new UnityEngine.iOS.LocalNotification(); notify.fireDate = System.DateTime.Now.AddSeconds(_delayTime); notify.alertBody = _content; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notify); UnityEngine.iOS.NotificationServices.ClearLocalNotifications(); #endif #if UNITY_ANDROID && !UNITY_EDITOR long time = (long)(_delayTime * 1000); using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { using (AndroidJavaObject obj_Activity = cls_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity")) { AndroidJavaClass cls_OpenNotificationAnd = new AndroidJavaClass("com.sd.glb.OpenNotification"); cls_OpenNotificationAnd.CallStatic("Init", obj_Activity); cls_OpenNotificationAnd.CallStatic("NotifyText", count++, time, _content); } } #endif }
//本地推送 你可以传入一个固定的推送时间 public static void NotificationMessage(string news, System.DateTime newDate, int RepeatType) { //推送时间需要大于当前时间 if (newDate > System.DateTime.Now) { #if UNITY_IPHONE UnityEngine.iOS.LocalNotification localNotification = new UnityEngine.iOS.LocalNotification(); localNotification.fireDate = newDate; localNotification.alertBody = news; localNotification.applicationIconBadgeNumber = 1; localNotification.hasAction = true; if (RepeatType == 1) { //是否每天定期循环 localNotification.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.ChineseCalendar; localNotification.repeatInterval = UnityEngine.iOS.CalendarUnit.Day; } else if (RepeatType == 2) { localNotification.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.ChineseCalendar; localNotification.repeatInterval = UnityEngine.iOS.CalendarUnit.Week; } localNotification.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(localNotification); #elif UNITY_ANDROID #endif } }
private void sendNotification(int id, TimeSpan delay, string title, string text, Color32 color) { var notificationParams = new NotificationParams { Id = id, Delay = delay, Title = title, Message = text, //Ticker = "Ticker", Sound = true, Vibrate = true, Light = true, SmallIcon = NotificationIcon.Bell, SmallIconColor = new Color(0.5f, 0.5f, 0.5f), LargeIcon = "app_icon" }; NotificationManager.SendCustom(notificationParams); //NotificationManager.SendWithAppIcon(delay, title, text, new Color(0, 0.6f, 1), NotificationIcon.Bell); //NotificationManager.Send(delay, title, text, new Color(0, 0.6f, 1)); //LocalNotification.SendNotification(id, delay, title, text, color); #if UNITY_IOS if (Application.platform == RuntimePlatform.IPhonePlayer) { UnityEngine.iOS.LocalNotification notification = new UnityEngine.iOS.LocalNotification(); notification.fireDate = DateTime.Now.Add(delay); notification.alertAction = "Alert"; notification.alertBody = text; notification.hasAction = false; NotificationServices.ScheduleLocalNotification(notification); } #endif }
void SetNotification(int id, int secondDelay, string title, string content, string soundName, string icon = "notificationsmallicon", string largeIcon = "notificationicon") { #if UNITY_EDITOR return; #endif #if UNITY_ANDROID // AndroidNotificationManager.Instance.CancelLocalNotification(id); // AndroidNotificationBuilder builder = new AndroidNotificationBuilder(id, title, content, secondDelay); // AndroidNotificationBuilder.NotificationColor color = new AndroidNotificationBuilder.NotificationColor(new Color((float)2 / 255, (float)199 / 255, 0, 1)); // builder.SetColor(color); // builder.SetSoundName(soundName); // builder.SetIconName(icon); // builder.SetLargeIcon(largeIcon); // builder.SetVibration(true); // builder.ShowIfAppIsForeground(false); // AndroidNotificationManager.Instance.ScheduleLocalNotification(builder); #elif UNITY_IOS var notif = new UnityEngine.iOS.LocalNotification(); notif.fireDate = System.DateTime.Now.AddSeconds(secondDelay); notif.alertAction = title; notif.alertBody = content; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notif); #endif }
public void RegisterAllNotifications(string title, string body, string largeIcon) { var notificationDate0000 = DateTime.Today; var now = DateTime.Now; var notificationDate0900 = notificationDate0000.AddHours(9); if (notificationDate0900 < now) { notificationDate0900 = notificationDate0900.AddDays(1); } #if UNITY_IOS string text = string.Format("{0}\n{1}", title, body); SushiDebug.Log("Schedule Local Notification"); UnityEngine.iOS.NotificationServices.ClearLocalNotifications(); UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications(); ClearAllNotifications(); // 09:00 UnityEngine.iOS.LocalNotification notification0900 = new UnityEngine.iOS.LocalNotification(); notification0900.fireDate = notificationDate0900; notification0900.alertBody = text; notification0900.alertAction = "Action"; notification0900.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName; notification0900.repeatInterval = UnityEngine.iOS.CalendarUnit.Day; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notification0900); #endif }
public void RegisterAllNotifications(string title, string body, string largeIcon, int localHours) { if (Application.platform == RuntimePlatform.IPhonePlayer) { #if UNITY_IOS var text = $"{title}\n{body}"; PlatformInterface.instance.logger.Log("Schedule Local Notification"); #pragma warning disable 618 UnityEngine.iOS.NotificationServices.ClearLocalNotifications(); UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications(); #pragma warning restore 618 #endif ClearAllNotifications(); // 09:00 #if UNITY_IOS #pragma warning disable 618 UnityEngine.iOS.LocalNotification notification0900 = new UnityEngine.iOS.LocalNotification { fireDate = PlatformEditor.GetNextLocalHours(localHours), alertBody = text, alertAction = "Action", soundName = UnityEngine.iOS.LocalNotification.defaultSoundName, repeatInterval = UnityEngine.iOS.CalendarUnit.Day }; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notification0900); #pragma warning restore 618 #endif } }
public static int SendNotification(int id, long delayMs, string title, string message, Color32 bgColor, bool sound = true, bool vibrate = true, bool lights = true, string bigIcon = "") { #if UNITY_ANDROID && !UNITY_EDITOR AndroidJavaClass pluginClass = new AndroidJavaClass(fullClassName); if (pluginClass != null) { pluginClass.CallStatic("SetNotification", id, delayMs, title, message, message, sound ? 1 : 0, vibrate ? 1 : 0, lights ? 1 : 0, bigIcon, "notify_icon_small", bgColor.r * 65536 + bgColor.g * 256 + bgColor.b, Application.bundleIdentifier); } return(id); #elif UNITY_IOS && !UNITY_EDITOR UnityEngine.iOS.LocalNotification notification = new UnityEngine.iOS.LocalNotification(); DateTime now = DateTime.Now; DateTime fireDate = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second).AddSeconds(delayMs); notification.fireDate = fireDate; notification.alertBody = message; notification.alertAction = title; notification.hasAction = false; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notification); return((int)fireDate.Ticks); #else return(0); #endif }
void Start() { // schedule notification to be delivered in 10 seconds UnityEngine.iOS.LocalNotification notif = new UnityEngine.iOS.LocalNotification(); notif.fireDate = DateTime.Now.AddSeconds(10); notif.alertBody = "Hello!"; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notif); }
public void CleanNotification() { LocalNotification l = new LocalNotification(); l.applicationIconBadgeNumber = -1; UnityEngine.iOS.NotificationServices.PresentLocalNotificationNow(l); LocalPush.Ins.StartCoroutine(delayOneFrame()); }
//清空所有本地消息 void CleanNotification() { UnityEngine.iOS.LocalNotification l = new UnityEngine.iOS.LocalNotification(); l.applicationIconBadgeNumber = -1; UnityEngine.iOS.NotificationServices.PresentLocalNotificationNow(l); UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications(); UnityEngine.iOS.NotificationServices.ClearLocalNotifications(); }
// Use this for initialization void Start() { // schedule notification to be delivered in 10 seconds UnityEngine.iOS.LocalNotification notif = new UnityEngine.iOS.LocalNotification(); notif.fireDate = DateTime.Now.AddSeconds(10); notif.alertBody = "Hello!"; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notif); }
public void PostIOSLocalNotification(DateTime time, string message) { var notif = new Local(); notif.fireDate = time; notif.alertBody = message; Notification.ScheduleLocalNotification(notif); }
public static void SetNotification(string message, int delayTime, int badgeNumber = 1) { var l = new LocalNotification(); l.applicationIconBadgeNumber = badgeNumber; l.fireDate = System.DateTime.Now.AddSeconds(delayTime); l.alertBody = message; NotificationServices.ScheduleLocalNotification(l); }
public static int CleanNotification(IntPtr l) { UnityEngine.iOS.LocalNotification localNotification = new UnityEngine.iOS.LocalNotification(); localNotification.applicationIconBadgeNumber = -1; UnityEngine.iOS.NotificationServices.PresentLocalNotificationNow(localNotification); UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications(); UnityEngine.iOS.NotificationServices.ClearLocalNotifications(); return(0); }
public void AddNotification() { #if UNITY_IOS LocalNotification l = new LocalNotification(); l.applicationIconBadgeNumber = 1; l.fireDate = System.DateTime.Now.AddSeconds(pushSeconds[0]); NotificationServices.ScheduleLocalNotification(l); #endif }
/** * local notificationを送る。 * どんだけ積まれてるかをどうやって制御しようかな。 * とりあえず追加するだけだな。 */ public void SendLocalNotification(DateTime localNotificationDate, string message, string action) { var notif = new UnityEngine.iOS.LocalNotification(); notif.fireDate = localNotificationDate; notif.alertBody = message; notif.alertAction = action; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notif); }
void Start() { // schedule notification to be delivered in 10 seconds var notif = new UnityEngine.iOS.LocalNotification(); notif.fireDate = DateTime.Now.AddSeconds(60); notif.alertBody = "Move your ass lazy hooman"; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notif); }
UnityEngine.iOS.LocalNotification getNotification(string notif, int time) { UnityEngine.iOS.LocalNotification notification = new UnityEngine.iOS.LocalNotification(); notification.fireDate = DateTime.Now.AddHours(time); // notification.applicationIconBadgeNumber = 1; notification.alertBody = notif; notification.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName; return(notification); }
void DidEnterRegion(object sender, CLLocationManager.DidEnterEventArgs e) { UnityEngine.iOS.LocalNotification notif = new UnityEngine.iOS.LocalNotification(); notif.alertBody = "Found beacon!"; UnityEngine.iOS.NotificationServices.PresentLocalNotificationNow(notif); Log("Found beacon."); locationManager.StartRangingBeaconsInRegion(beaconRegion); }
void DidExitRegion(object sender, CLLocationManager.DidExitEventArgs e) { UnityEngine.iOS.LocalNotification notif = new UnityEngine.iOS.LocalNotification(); notif.alertBody = "Lost beacon!"; UnityEngine.iOS.NotificationServices.PresentLocalNotificationNow(notif); Log("Left region."); locationManager.StopRangingBeaconsInRegion(beaconRegion); }
private void SendLocalNotification() { #if UNITY_IOS UnityEngine.iOS.LocalNotification __notification = new UnityEngine.iOS.LocalNotification(); __notification.alertAction = LocalizedString.GetString("notificationTitle"); __notification.alertBody = LocalizedString.GetString("notificationDesc"); #elif UNITY_ANDROID AndroidNotification __notification = new AndroidNotification(); __notification.Title = LocalizedString.GetString("notificationTitle"); __notification.Text = LocalizedString.GetString("notificationDesc"); #endif for (int i = 0; i < 5; i++) { switch (i) { #if UNITY_IOS case 0: __notification.fireDate = System.DateTime.Now.AddDays(1); break; case 1: __notification.fireDate = System.DateTime.Now.AddDays(5); break; case 2: __notification.fireDate = System.DateTime.Now.AddDays(10); break; case 3: __notification.fireDate = System.DateTime.Now.AddDays(14); break; case 4: __notification.fireDate = System.DateTime.Now.AddDays(20); break; #elif UNITY_ANDROID case 0: __notification.FireTime = System.DateTime.Now.AddDays(1); break; case 1: __notification.FireTime = System.DateTime.Now.AddDays(5); break; case 2: __notification.FireTime = System.DateTime.Now.AddDays(10); break; case 3: __notification.FireTime = System.DateTime.Now.AddDays(14); break; case 4: __notification.FireTime = System.DateTime.Now.AddDays(20); break; #endif } #if UNITY_IOS UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(__notification); #elif UNITY_ANDROID AndroidNotificationCenter.SendNotification(__notification, "channel_id"); #endif } }
public void makeRepeatingNotificationiOS(string title, string content, int delay, UnityEngine.iOS.CalendarUnit u) { UnityEngine.iOS.LocalNotification n = new UnityEngine.iOS.LocalNotification(); n.fireDate = System.DateTime.Now.AddSeconds(delay); n.repeatInterval = u; n.alertBody = content; n.hasAction = true; //Set that pushing the button will launch the application UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(n); }
public void SetNotification(string title, string body, double second) { UnityEngine.iOS.LocalNotification noti = new UnityEngine.iOS.LocalNotification(); noti.alertAction = title; noti.alertBody = body; noti.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName; noti.applicationIconBadgeNumber = 1; noti.fireDate = System.DateTime.Now.AddSeconds(second); UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(noti); }
public void ClearNotification() { #if UNITY_IOS LocalNotification l = new LocalNotification(); l.applicationIconBadgeNumber = -1; NotificationServices.PresentLocalNotificationNow(l); NotificationServices.CancelAllLocalNotifications(); NotificationServices.ClearLocalNotifications(); #endif }
private DateTime getIosUtcDateTime(LocalNotification iOSNotification) { var userInfo = iOSNotification.userInfo; if (userInfo != null && userInfo.Contains(UTC_DATE_KEY)) { return(TimeExtensions.utcDateTimeFromFileTimeString((string)userInfo[UTC_DATE_KEY], DateTime.MinValue)); } return(DateTime.MinValue); }
public void Schedule(int seconds, string description) { #if UNITY_IOS UnityEngine.iOS.LocalNotification notification = new UnityEngine.iOS.LocalNotification(); notification.fireDate = DateTime.Now.AddSeconds(seconds); notification.alertBody = description; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notification); #endif }
public void RegisterSingleNotification(string title, string body, int afterMs, string largeIcon) { #if UNITY_IOS UnityEngine.iOS.LocalNotification n = new UnityEngine.iOS.LocalNotification(); n.fireDate = System.DateTime.Now.AddMilliseconds(afterMs); n.alertBody = body; n.alertAction = "Action"; n.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(n); #endif }
static void Clear() { UnityEngine.iOS.LocalNotification ln = new UnityEngine.iOS.LocalNotification() { applicationIconBadgeNumber = -1 }; UnityEngine.iOS.NotificationServices.PresentLocalNotificationNow(ln); UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications(); UnityEngine.iOS.NotificationServices.ClearLocalNotifications(); }
void ClearLocalNotifications() { #if UNITY_IOS UnityEngine.iOS.LocalNotification m_LocalNotification = new UnityEngine.iOS.LocalNotification(); m_LocalNotification.applicationIconBadgeNumber = -1; UnityEngine.iOS.NotificationServices.PresentLocalNotificationNow(m_LocalNotification); UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications(); UnityEngine.iOS.NotificationServices.ClearLocalNotifications(); EtceteraBinding.setBadgeCount(0); #endif }
void OnApplicationPause (bool pauseStatus) { #if UNITY_IOS if (pauseStatus) { UnityEngine.iOS.LocalNotification notif = new UnityEngine.iOS.LocalNotification (); notif.fireDate = DateTime.Now.AddSeconds (1800); notif.alertBody = "Why not try again!"; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification (notif); } #endif }
// Use this for initialization void OnEnable() { #if UNITY_IOS UnityEngine.iOS.LocalNotification notif = new UnityEngine.iOS.LocalNotification(); notif.fireDate = System.DateTime.Now.AddSeconds(10); notif.alertBody = "Hello LEO!"; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notif); #endif string message = "This is a local notification! This is a super long one to show how long we can make a notification. " + "On Android this will appear as an extended notification."; NativeToolkit.ScheduleLocalNotification("Hello there", message, 1, 0, "sound_notification", true, "ic_notification", "ic_notification_large"); Debug.Log ("Message: " + message); }
public static void SendNotification(int id, long delay, string title, string message, Color32 bgColor, bool sound = true, bool vibrate = true, bool lights = true, string bigIcon = "", NotificationExecuteMode executeMode = NotificationExecuteMode.Inexact) { #if UNITY_ANDROID && !UNITY_EDITOR AndroidJavaClass pluginClass = new AndroidJavaClass(fullClassName); if (pluginClass != null) { pluginClass.CallStatic("SetNotification", id, delay * 1000L, title, message, message, sound ? 1 : 0, vibrate ? 1 : 0, lights ? 1 : 0, bigIcon, "notify_icon_small", bgColor.r * 65536 + bgColor.g * 256 + bgColor.b, (int)executeMode, mainActivityClassName); } #elif UNITY_IOS && !UNITY_EDITOR UnityEngine.iOS.LocalNotification iNoti = new UnityEngine.iOS.LocalNotification(); iNotiMap.Add(id, iNoti); iNoti.fireDate = DateTime.Now.AddSeconds ((double) delay); iNoti.alertAction = title; iNoti.alertBody = message; iNoti.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName; iNoti.hasAction = false; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(iNoti); #endif }
public static extern void CancelLocalNotification(LocalNotification notification);
public static extern void PresentLocalNotificationNow(LocalNotification notification);
public static extern void ScheduleLocalNotification(LocalNotification notification);