I’ve been trying to make a notification appear when user doesn’t launch the game for 24 hours. I tried using few plugins from asset store but none of them worked after closing down the app, ony when it was running in the background. I was thinking about using Firebase but i’m not shute if it’s a good option, if possible i would like to have notification even offline.
I was wondering how is it done in other Unity games?
3 Answers
3I needed to do this a short time ago, to notify my players, that the spell was ready in my game. I discovered that I needed to schedule the notification in the future, when the notification was ready. Since I’m not a good programmer, I’ve researched something in the asset store and found a tool that accesses native Android features so I can easily schedule my notifications! I only paid $ 9.90, and it also has several other spectacular functions!
A local notification does not require any server integration (e.g: Firebase).
The way it works, is you schedule a notification to show up after some time (for example - after 24 hours).
When you launch the game, you can cancel the notification, and when you leave the game, you reschedule it.
The operating system (Android and iOS) both take care of registering the information about the notification, so it’s not necessary to keep the game / app running in order for it to work.
There’s another, more complex case where the device is rebooted in between. I believe there may be solutions for that, but i am not 100% sure.
For implementation, if you’re not familiar with the native code required for this (on each platform), your best bet would be to use a plugin that provides this functionality.
Thanks for your answer. I managed to achieve what i intended to on iOS using Unitys NotificationServices. I still need to do something about android. I have some experience with android native code so I think I'll manage to do it but it would be great if I could get some pointers :) If I remember correctly, on android i used BroadcastReceiver for notifications. I also read something about setting alarms for notifications. Is any of those a correct way?
– SrubaLocal notifications work well if the app is closed. But, it should not be force-stopped (on Android), as any activity of the app is stopped by OS in that case - it’s done on purpose by Google. Some Android devices (many ASUS models, f.e., but not only) unfortunately force-stop any applications with no Activities, except of some built-in white-list, to save power. In that case you can’t do anything, even push notifications won’t help (as they are blocked for force-stopped apps too). Also, on Android scheduled local notifications are not by default persistent after a device reboot, but there are ways to implement it. There are some Unity assets (such as our UTNotifications) which can do it. But of course you also can implement it on your own using native plugins.
I have used the Simple Android Notifications Free plugin from Hippo in my project. However, I noticed that notifications are shown when my game is in the background, but they do not appear if the game is killed. I need your help to find a method that allows notifications to be displayed even when the game is killed. I don’t want to use FCM. Is there any other solution?
– hazelfatimaabbasI’m using the Mobile Notifications package in Unity to implement local notifications. It works perfectly when the game is running in the background, but when the game is completely closed (killed), the notifications sometimes work and sometimes don’t. What could be the issue, and can anyone recommend a reliable solution?
– hazelfatimaabbas
Can you please let me know which asset you used to create local notifications for iOS while app is running in background? I’m looking for one that can do that. Thanks
– baopham