コード例 #1
0
    public void CreateRandomNotification(System.DateTime time)
    {
        var channel = new AndroidNotificationChannel()
        {
            Id          = "instajong",
            Name        = "Default Instajong Channel",
            Importance  = Importance.Default,
            Description = "Generic notifications"
        };

        AndroidNotificationCenter.RegisterNotificationChannel(channel);

        _notification _n = GetRandomNotification();

        var _NewNotification = new AndroidNotification()
        {
            Title     = _n._Header,
            Text      = _n._Message,
            Color     = _n._Color,
            FireTime  = time,
            SmallIcon = "icon_0"
        };

        identifier = AndroidNotificationCenter.SendNotification(_NewNotification, channel.Id);

        AndroidNotificationCenter.NotificationReceivedCallback receivedCallback = delegate(AndroidNotificationIntentData data)
        {
            var msg = "Notification received : " + data.Id + "\n";
            msg += "\n Notification received: ";
            msg += "\n Title: " + data.Notification.Title;
            msg += "\n Body: " + data.Notification.Text;
            msg += "\n Channel: " + data.Channel;
        };

        AndroidNotificationCenter.OnNotificationReceived += ReceivedNotificationHandler;

        var notificationIntentData = AndroidNotificationCenter.GetLastNotificationIntent();

        if (notificationIntentData != null)
        {
            Debug.Log("App was opened with notification!");
        }
    }
コード例 #2
0
    public void CreateIosNotification(System.TimeSpan span)
    {
        var _time = new iOSNotificationTimeIntervalTrigger()
        {
            TimeInterval = span,
            Repeats      = false
        };


        _notification n = GetRandomNotification();

        var _notification = new iOSNotification()
        {
            Title                        = n._Header,
            Body                         = n._Message,
            ShowInForeground             = true,
            ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
            CategoryIdentifier           = "simple_category",
            ThreadIdentifier             = "instajong_thread",
            Trigger                      = _time
        };

        iOSNotificationCenter.ScheduleNotification(_notification);
    }