- Home /
Local notification with closed app
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?
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
Answer by liortal · Apr 05, 2017 at 03:48 PM
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?
You use the system's Alarm$$anonymous$$anager to time a specific thing to occur. you give it a PendingIntent object, that specifies what should happen (wrap an Intent to call your broadcast receiver in it).
In your broadcast receiver, which catches the broadcast notification as it occurs, you build a notification object and present it to the user. Easy as pie :)
I hate to push my services too strong, but just in case you need my professional assistance, feel free to contact me here: https://www.fiverr.com/lysergide
Answer by AquinoJ · Apr 10, 2019 at 08:34 PM
I 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!
https://assetstore.unity.com/packages/tools/integration/native-android-toolkit-mt-139365
Answer by Yuriy-Ivanov · Apr 07, 2017 at 02:42 PM
Local 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.