Push¶
Push registers for remote push and reports tokens and
messages. It needs the notifications capability too, so use
use = ["notifications", "push"] under [plugins], with notifications = true and
remote_notifications = true under [permissions]. See the
Push guide.
Remote push: the device token your server needs, and the messages it sends.
Requires the notifications capability, which presents pushes and reports
taps. iOS uses APNs. Android uses Firebase Cloud Messaging and needs your
project's google-services.json:
[plugins]
use = ["notifications", "push"]
[permissions]
notifications = true
remote_notifications = true
[plugins.push]
google_services_file = "google-services.json"
Without that file an Android app still builds and launches, and
get_device_token raises NativeModuleError with the code
not_configured.
Example
Subscribe at the top of your entry module to hear a message that starts the app with no screen, as Python's startup imports that module first.
Classes:
| Name | Description |
|---|---|
PushMessage |
A remote message the app received. |
Push |
Remote push interface. |
PushMessage
dataclass
¶
Push
¶
Remote push interface.
Raises:
| Type | Description |
|---|---|
NativeModuleError
|
If the native module fails, or with the code
|
Methods:
| Name | Description |
|---|---|
get_device_token |
Register for remote push and return this device's token. |
on_token |
Call |
on_message |
Call |
get_device_token
async
staticmethod
¶
Register for remote push and return this device's token.
On iOS it's a lowercase hex APNs token, and on Android an FCM registration token. A simulator without APNs access can't get one.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The token, or |
Raises:
| Type | Description |
|---|---|
NativeModuleError
|
With the code |
on_token
staticmethod
¶
Call callback with each new token, so your server stays current.
Subscribing registers for remote push on iOS. A token issued before the first subscriber is delivered to it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[str], None]
|
Receives the token string. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[], None]
|
A zero-argument function that unsubscribes. |
on_message
staticmethod
¶
on_message(
callback: Callable[[PushMessage], None],
) -> Callable[[], None]
Call callback for each remote message the app gets to process.
- In the foreground, every push.
- In the background, or with no process running, a silent push: one
with
content-availableon iOS, or a data message on Android. The OS shows a visible push by itself and tells the app only if it's tapped, throughNotifications.on_response.
A message from before the first subscriber is delivered to it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[PushMessage], None]
|
Receives a |
required |
Returns:
| Type | Description |
|---|---|
Callable[[], None]
|
A zero-argument function that unsubscribes. |