61 lines
2.5 KiB
C#
61 lines
2.5 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
|
|
namespace Thousandto.Code.Logic
|
|
{
|
|
public class LocalIPhoneNotification
|
|
{
|
|
//清空所有本地消息
|
|
public static void CleanNotification()
|
|
{
|
|
#if UNITY_IPHONE
|
|
UnityEngine.iOS.LocalNotification l = new UnityEngine.iOS.LocalNotification();
|
|
l.applicationIconBadgeNumber = -1;
|
|
UnityEngine.iOS.NotificationServices.PresentLocalNotificationNow(l);
|
|
UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications();
|
|
UnityEngine.iOS.NotificationServices.ClearLocalNotifications();
|
|
#endif
|
|
|
|
}
|
|
|
|
//本地推送
|
|
public static void NotificationMessage(string message, int hour, int minute, bool isRepeatDay)
|
|
{
|
|
#if UNITY_IPHONE
|
|
int year = System.DateTime.Now.Year;
|
|
int month = System.DateTime.Now.Month;
|
|
int day = System.DateTime.Now.Day;
|
|
System.DateTime newDate = new System.DateTime(year, month, day, hour, minute, 0);
|
|
NotificationMessage(message, newDate, isRepeatDay);
|
|
#endif
|
|
}
|
|
//本地推送 你可以传入一个固定的推送时间
|
|
public static void NotificationMessage(string message, System.DateTime newDate, bool isRepeatDay)
|
|
{
|
|
#if UNITY_IPHONE
|
|
//推送时间需要大于当前时间
|
|
if (newDate > System.DateTime.Now)
|
|
{
|
|
UnityEngine.iOS.LocalNotification localNotification = new UnityEngine.iOS.LocalNotification();
|
|
localNotification.fireDate = newDate;
|
|
localNotification.alertBody = message;
|
|
//不要红点
|
|
//localNotification.applicationIconBadgeNumber = 1;
|
|
localNotification.hasAction = true;
|
|
if (isRepeatDay)
|
|
{
|
|
//是否每天定期循环
|
|
localNotification.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.ChineseCalendar;
|
|
localNotification.repeatInterval = UnityEngine.iOS.CalendarUnit.Day;
|
|
}
|
|
localNotification.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName;
|
|
UnityEngine.iOS.NotificationServices.RegisterForNotifications(UnityEngine.iOS.NotificationType.Badge | UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Sound);
|
|
UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(localNotification);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
}
|
|
} |