unity安卓和IOS的本地消息推送

本文介绍了如何在Unity中实现在安卓和iOS设备上的本地消息推送,提供了简单的代码实例,帮助开发者理解和应用这一功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值