push

package
v0.11.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package push receives push notifications on phones: APNs on iOS, and Firebase Cloud Messaging on Android. It tells the token that the app's server sends to.

iOS needs the Push Notifications capability in the app's provisioning profile. Android needs a Firebase project: give Configure its values, as in its google-services.json. Elsewhere its functions report errors.ErrUnsupported.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(ctx context.Context, f Firebase) error

Configure sets up Firebase, on Android. Call it before Register. iOS ignores it.

func OnMessage

func OnMessage(fn func(data []byte)) (off func())

OnMessage calls fn on the main thread as a push arrives while the app runs, with what it carries, as JSON.

func OnOpened

func OnOpened(fn func(data []byte)) (off func())

OnOpened calls fn on the main thread as the user taps a push's notification, with what it carries, as JSON: also the tap that launched the app, once this listens, so call it as the app is ready.

func OnToken

func OnToken(fn func(token string)) (off func())

OnToken calls fn on the main thread as the token changes.

func Register

func Register(ctx context.Context) (string, error)

Register asks the user to allow notifications, and returns the token that the app's server sends them to, which may change: see OnToken. Call it off the main goroutine, as it waits for the user.

Types

type Firebase

type Firebase struct {
	ProjectID string `json:"projectId"`
	AppID     string `json:"appId"`
	APIKey    string `json:"apiKey"`
	SenderID  string `json:"senderId"`
}

Firebase is what Android's messaging needs of the app's Firebase project.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL