Я пытаюсь написать плагин для Unity3D, чтобы получить обратный вызов, когда пользователь нажимает на локальное или push-уведомление, когда приложение закрыто. Я попробовал Prime31 Etcetera Plugin для этого, но он не работает. Поэтому я решил написать свой собственный плагин. Я попробовал несколько методов, но это не сработало. Может ли кто-нибудь вести меня, как это сделать?Уведомление щелкнуло Обратный звонок
2
A
ответ
1
Я просто должен был сделать это несколько дней назад. Вот класс, который я использовал:
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.iOS;
using System.Collections;
public class Notifications : MonoBehaviour
{
private void Awake()
{
// If app launched for the first time, set up a notification
if (!PlayerPrefs.HasKey("firstLaunch"))
{
UnityEngine.iOS.NotificationServices.ClearLocalNotifications();
UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications();
PlayerPrefs.SetInt("firstLaunch", 0);
UnityEngine.iOS.NotificationServices.RegisterForNotifications(NotificationType.Alert | NotificationType.Badge | NotificationType.Sound);
var notification = new UnityEngine.iOS.LocalNotification();
notification.alertAction = "Title of the notification";
notification.alertBody = "Body of the notification";
// I set this to -1 because I didn't want to have the badge on the app icon
notification.applicationIconBadgeNumber = -1;
var currentDate = DateTime.Now;
var targetDate = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 9, 15, 00, DateTimeKind.Local);
targetDate = (currentDate < targetDate) ? targetDate : targetDate.AddDays(1);
// Set the date and time the notification will fire
notification.fireDate = targetDate;
// In my case in wanted to repeat it everyday at 9:15 AM
notification.repeatInterval = UnityEngine.iOS.CalendarUnit.Day;
UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notification);
}
}
private void OnApplicationPause(bool state)
{
// If app returns to foreground
if (!state)
{
// If this count > 0, then a notification has been clicked
if (UnityEngine.iOS.NotificationServices.localNotificationCount > 0)
{
// Do stuff
}
UnityEngine.iOS.NotificationServices.ClearLocalNotifications();
}
}
}
Надеюсь, это поможет!
Смежные вопросы
- 1. Обратный звонок при переходе CSS
- 2. Обратный звонок на mdMenu close
- 3. Отклонить текущее уведомление о Действии щелкнуло
- 4. Обратный звонок от chooser
- 5. Обратный звонок с XPCOM
- 6. Обратный звонок WCF-клиента
- 7. Обратный звонок в Python
- 8. Обратный звонок iTunes
- 9. Обратный звонок в nodejs
- 10. EnumDisplayMonitors EnumProc Обратный звонок
- 11. Обратный звонок с временем
- 12. Функции JavaScript Обратный звонок
- 13. Обратный звонок с CompletableFuture
- 14. Обратный звонок с NetTCPBinding
- 15. Обратный звонок не выполняется
- 16. jQuery Ajax - Обратный звонок
- 17. Keras Fit_generator Обратный звонок
- 18. Обратный звонок Последняя активность
- 19. нерешённая ссылка: Обратный звонок
- 20. Обратный звонок для stopUpdateLocation
- 21. Обратный звонок для cellForRowAtIndexPath?
- 22. Обратный звонок или обещание?
- 23. Обратный звонок с Classie.js
- 24. Обратный звонок из FireBreath
- 25. jQuery Анимация Обратный звонок
- 26. Обратный звонок после JSON
- 27. Кнопка Fltk Обратный звонок
- 28. Обратный звонок/Закрытие Выпуск
- 29. Аякса список обратный звонок
- 30. Обратный звонок не набирается
Это для iOS, Unity предоставляет службу уведомлений для iOS, но не для Android. Как я могу достичь этого в андроиде? –
К сожалению, я не обращал внимания на теги. Я никогда не делал этого для Android, извините. Может быть, вы можете попробовать этот плагин, это бесплатно! (Https://github.com/Agasper/unity-android-notifications) – Whatever