Skip to content

Commit 1f4941d

Browse files
committed
doc: installation & usage
1 parent 7382b8b commit 1f4941d

1 file changed

Lines changed: 71 additions & 21 deletions

File tree

README.md

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929
<p align="center">
3030
<a href="#about">About</a> •
31+
<a href="#caution">Caution</a> •
3132
<a href="#installation">Installation</a> •
33+
<a href="#customize">Customize</a> •
3234
<a href="#usage">Usage</a> •
3335
<a href="#api">API</a> •
3436
<a href="#contribute">Contribute</a> •
@@ -41,14 +43,26 @@
4143

4244
# About
4345

44-
This plugin help send Local Notification (Android/iOS). You can use it to send notifications to user at the time you want (No Internet need).
46+
This plugin help send Local Notification (Android/iOS). You can use it to send notifications to user at the time you want, or send daily notification at the specific time you want.
4547

4648
This plugin just handle Local Notification, it not support Remote Notification.
4749

4850
Was build using automation scripts combine with CI/CD to help faster the release progress and well as release hotfix which save some of our times.
4951

5052
Support Godot 3 & 4.
5153

54+
# Caution
55+
56+
This plugin to support latest Android (13+) and iOS. But there is some thing you must know before using.
57+
58+
The notification time may delay a few seconds or even minutes. If the user turn on Battery Optimize mode on their phone, your notifications will delay longer or even not display. The reason for that is i'm trying to not using `unsafe` permissions (Android). Cause it's way to risky, can crash your apps/games and not worth it.
59+
60+
On iOS, the minimal `repeating_interval` is 60.
61+
62+
You shouldn't show notification when they using your app/game too, it's just annoying them. Schedule to send notifications at specific times like when energy is full, when the tree are mature or st like that...
63+
64+
When showing notifications, try to store their tags somewhere, in case you want to remove and schedule new set of notifications.
65+
5266
# Installation
5367

5468
## Android
@@ -65,6 +79,29 @@ Download the [ios plugin](https://github.com/kyoz/godot-local-notification/relea
6579

6680
Enable `LocalNotification` plugin in your ios export preset
6781

82+
# Customize
83+
84+
On Android, you can change the color of notification by adding `notification-color.xml` to your app/game's `android/build/res/values` folder with content like so:
85+
86+
```
87+
<?xml version="1.0" encoding="utf-8"?>
88+
<resources>
89+
<color name="notification_color">#000000</color>
90+
</resources>
91+
```
92+
93+
Default color are black (#000000)
94+
95+
You should also use [this](https://romannurik.github.io/AndroidAssetStudio/icons-notification.html) or [Image Asset Studio](https://developer.android.com/studio/write/create-app-icons) (in Android Studio) to generate your notification icons too, and put them in mipmap folders.
96+
97+
The name of notification icon must be `notification_icon.png`
98+
99+
```
100+
android/build/res/mipmap*/notification_icon.png
101+
```
102+
103+
On iOS, the notification icon will be the default App Icon so there's no need to do anything except design your beautiful icon.
104+
68105
# Usage
69106

70107
You will need to add an `autoload` script to use this plugin more easily.
@@ -75,13 +112,15 @@ Then you can easily use it anywhere with:
75112

76113
```gdscript
77114
LocalNotification.init()
78-
LocalNotification.show()
79115
80-
# Godot 3
81-
LocalNotification.connect("on_completed", self, "_on_completed")
116+
LocalNotification.requestPermission()
117+
118+
# To ensure the request process is done, you can use the signal as you like,
119+
# I prefer this solution
120+
yield(LocalNotification, "on_permission_request_completed")
82121
83-
# Godot 4
84-
LocalNotification.on_completed.connect(_on_completed)
122+
if LocalNotification.isPermissionGranted():
123+
LocalNotification.show(title, message, 30, 10)
85124
```
86125

87126
Why have to call `init()`. Well, if you don't want to call init, you can change `init()` to `_ready()` on the `autoload` file. But for my experience when using a lots of plugin, init all plugins on `_ready()` is not a good idea. So i let you choose whenever you init the plugin. When showing a loading scene...etc...
@@ -92,30 +131,41 @@ For more detail, see [examples](./example/)
92131

93132
## Methods
94133

95-
```gdscript
96-
void show() # sdfjo
97-
```
134+
> `isPermissionGranted`() -> bool
98135
99-
## Signals
136+
Use to check current status of permission. return true if permission was granted, false if it is not granted or denied
100137

101-
```gdscript
102-
signal on_error(error_code) # request fail, return error_code
103-
signal on_completed() # request and show completed
104-
```
138+
> `requestPermission`() -> void
139+
140+
Use to request permission to show local notification. On Android <= 12, the permission is alway granted. But you should call it anyway, to have clean code base for all version, platforms.
141+
142+
> `openAppSetting`() -> void
105143
106-
## Error Codes
144+
Use to open app setting. When user denied one on iOS and twice on Android, the permission dialog will never appear again. So i make this as a handy method for user to jump to App Setting so they can re-active notification.
107145

108-
> `ERROR_GOOGLE_PLAY_UNAVAILABLE`
146+
*WARNING*: After calling `requestPermission()` if `isPermissionGranted()` still return `false`. It's mean user has denied the permission. You can use this function to help user easily toggle notification on. But you should prompt a dialog or st like that to let user know, or choose to open App Setting or not. Just don't jump out of the app without any notify, they will confuse and may never go back to your app again :(
109147

110-
Android only. Happen when there's no Google Play Services on the user phone. Rarely happen. Cause normally, they will install your app through Google Play.
148+
> `show`(title, message, interval, tag) -> void
111149
112-
> `ERROR_NO_ACTIVE_SCENE`
150+
Use to show a notification after `interval` seconds. The `interval` must be greater than 0. And on `iOS` the notification may not show if the app are running on foreground.
113151

114-
iOS only. Happen when the plugin can't find active scene. Make sure you calling `show()` method when the app are runing in foreground.
152+
> `showRepeating`(title, message, interval, repeat_interval, tag) -> void
115153
116-
> `ERROR_UNKNOWN`
154+
Just like `show()` function but the notification will keep repeat after `repeat_interval`.
117155

118-
Is rarely happen too.
156+
> `showDaily`(title, message, at_hour, at_minute, tag) -> void
157+
158+
Show daily notification at your choosen hour and minute.
159+
160+
> `cancel`(tag) -> void
161+
162+
Cancel a notification with it tag. When showing notifications, you should store their tags somewhere, in case you want to cancel em and schedule new set of notifications.
163+
164+
## Signals
165+
166+
```gdscript
167+
signal on_permission_request_completed() # emit when the permission request flow completed
168+
```
119169

120170
# Contribute
121171

0 commit comments

Comments
 (0)