iOS-Unity 中的预定本地通知

Scheduled local notifications in iOS-Unity

我找不到有关发送预定本地通知的合适教程

我想到了这个,但下面的代码不起作用

void Start()

    {
        LocalNotification notif = new LocalNotification();

        notif.fireDate          = System.DateTime.Now.AddSeconds(5f);

        notif.alertBody         = "Hey";    

        NotificationServices.ScheduleLocalNotification(notif);

     }

请帮我解决这个问题

您必须先致电 "NotificationServices.RegisterForNotifications"。 请参见 => Unity Documentation

这样试试:

void ScheduleNotificationForiOSWithMessage (string text, System.DateTime fireDate)
{
    if (Application.platform == RuntimePlatform.IPhonePlayer) {
        LocalNotification notification = new LocalNotification ();
        notification.fireDate = fireDate;
        notification.alertAction = "Alert";
        notification.alertBody = text;
        notification.hasAction = false;
        NotificationServices.ScheduleLocalNotification (notification);

        #if UNITY_IOS
        NotificationServices.RegisterForLocalNotificationTypes (LocalNotificationType.Alert | LocalNotificationType.Badge);
        #endif
    }        
}