1.如果只想看IOS的本地消息推送的话,请参考雨凇的博客:http://www.xuanyusong.com/archives/2632
2.以下是安卓和IOS消息推送的简单实例,上代码:
using UnityEngine;
using System.Collections;
using System;
public class NewBehaviourScript : MonoBehaviour {
#if !UNITY_EDITOR && UNITY_ANDROID
private AndroidJavaClass localPushService;
#endif
//本地推送
public void NotificationMessage(string message, int hour, bool isRepeatDay)
{
#if !UNITY_EDITOR && 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, 0, 0);
NotificationMessage(message, newDate, isRepeatDay);
#elif !UNITY_EDITOR && UNITY_ANDROID
//@Remark Android层做了限制通知条数最多不能超过40条,ID号也不能超过40条
//if(id >= 40) return;
int year = System.DateTime.Now.Year;
int month = System.DateTime.Now.Month;
int day = System.DateTime.Now.Day;
//int fixHour = Mathf.Clamp(hour, 0, 23);
//int fixMinute = Mathf.Clamp(Minute, 0, 59);
//System.DateTime newDate = new System.DateTime(year, month, day, fixHour, fixMinute, seconds);
System.DateTime newDate = new System.DateTime(year, month, day, hour, 0, 0);
NotificationMessage(message, newDate, isRepeatDay);
#endif
}
//本地推送 你可以传入一个固定的推送时间
public void NotificationMessage(string message, System.DateTime newDate, bool isRepeatDay)
{
#if !UNITY_EDITOR && UNITY_IPHONE
//推送时间需要大于当前时间
if (newDate > System.DateTime.Now)
{
LocalNotification localNotification = new LocalNotification();
localNotification.fireDate = newDate;
localNotification.al