Skip to content

Instantly share code, notes, and snippets.

@cadenburleson
Created January 26, 2021 03:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cadenburleson/45a704e40e4485fb7ea7acefa310e091 to your computer and use it in GitHub Desktop.
Save cadenburleson/45a704e40e4485fb7ea7acefa310e091 to your computer and use it in GitHub Desktop.
using System;
//using System.Collections; | Probably not needed
//using System.Collections.Generic; | Probably not needed
//using UnityEditor; | Probably not needed
using UnityEngine;
public class Notify : MonoBehaviour
{
private string title = "Ballsack is warmed";
private string content = "Do your 20 push-ups for today!";
// Start is called before the first frame update
void Start()
{
#if UNITY_IOS
UnityEngine.iOS.NotificationServices.RegisterForNotifications(UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Badge | UnityEngine.iOS.NotificationType.Sound);
#endif
}
private void OnApplicationPause(bool pause)
{
#if UNITY_IOS
UnityEngine.iOS.NotificationServices.ClearLocalNotifications();
UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications();
if (pause)
{
DateTime dateToNotify = DateTime.Now.AddSeconds(30);
UnityEngine.iOS.LocalNotification notif = new UnityEngine.iOS.LocalNotification();
notif.fireDate = dateToNotify;
notif.alertTitle = title;
notif.alertBody = content;
notif.repeatInterval = UnityEngine.iOS.CalendarUnit.Minute;
UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notif);
}
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment